SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
matrix_concept.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <concepts>
16 #include <cstddef>
17 #include <limits>
18 
20 
21 namespace seqan3::detail
22 {
23 
26 template <typename score_type>
27 constexpr score_type matrix_inf = std::numeric_limits<score_type>::max();
28 
40 template <typename matrix_t>
41 concept matrix = requires (std::remove_cvref_t<matrix_t> m) {
43 
47  typename std::remove_cvref_t<matrix_t>::value_type;
51  typename std::remove_cvref_t<matrix_t>::reference;
55  typename std::remove_cvref_t<matrix_t>::size_type;
56 
61  {
62  m.cols()
63  } -> std::same_as<typename std::remove_cvref_t<matrix_t>::size_type>;
65 
70  {
71  m.rows()
72  } -> std::same_as<typename std::remove_cvref_t<matrix_t>::size_type>;
74 
79  {
80  m.at(matrix_coordinate{})
81  } -> std::same_as<typename std::remove_cvref_t<matrix_t>::reference>;
83 
85  };
88 
100 template <matrix matrix1_t, matrix matrix2_t>
101  requires std::equality_comparable_with<typename matrix1_t::reference, typename matrix2_t::reference>
102 inline bool operator==(matrix1_t const & lhs, matrix2_t const & rhs) noexcept
103 {
104  if (lhs.rows() != rhs.rows())
105  return false;
106 
107  if (lhs.cols() != rhs.cols())
108  return false;
109 
110  for (size_t row = 0u; row < lhs.rows(); ++row)
111  for (size_t col = 0u; col < lhs.cols(); ++col)
112  if (matrix_coordinate co{row_index_type{row}, column_index_type{col}}; lhs.at(co) != rhs.at(co))
113  return false;
114 
115  return true;
116 }
117 
124 template <matrix matrix1_t, matrix matrix2_t>
125  requires std::equality_comparable_with<typename matrix1_t::reference, typename matrix2_t::reference>
126 inline bool operator!=(matrix1_t const & lhs, matrix2_t const & rhs) noexcept
127 {
128  return !(lhs == rhs);
129 }
131 
132 } // namespace seqan3::detail
The <concepts> header from C++20's standard library.
requires requires
The rank_type of the semi-alphabet; defined as the return type of seqan3::to_rank....
Definition: alphabet/concept.hpp:164
Provides seqan3::detail::matrix_index, seqan3::detail::matrix_coordinate and associated strong types.
matrix_index< size_t > matrix_coordinate
A coordinate type to access an element inside of a two-dimensional matrix.
Definition: matrix_coordinate.hpp:178
T max(T... args)
T operator!=(T... args)