SeqAn3  3.2.0
The Modern C++ library for sequence analysis.
matrix_coordinate.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 <type_traits>
17 
22 
23 namespace seqan3::detail
24 {
29 template <typename index_type>
30  requires (std::integral<index_type> || simd_index<index_type>)
31 struct column_index_type : detail::strong_type<index_type, column_index_type<index_type>>
32 {
34  using detail::strong_type<index_type, column_index_type<index_type>>::strong_type;
35 };
36 
42 template <std::signed_integral index_type>
43 column_index_type(index_type) -> column_index_type<std::ptrdiff_t>;
44 
46 template <std::unsigned_integral index_type>
47 column_index_type(index_type) -> column_index_type<size_t>;
48 
50 template <simd_index index_type>
51 column_index_type(index_type) -> column_index_type<index_type>;
53 
58 template <typename index_type>
59  requires (std::integral<index_type> || simd_index<index_type>)
60 struct row_index_type : detail::strong_type<index_type, row_index_type<index_type>>
61 {
63  using detail::strong_type<index_type, row_index_type<index_type>>::strong_type;
64 };
65 
71 template <std::signed_integral index_type>
72 row_index_type(index_type) -> row_index_type<std::ptrdiff_t>;
73 
75 template <std::unsigned_integral index_type>
76 row_index_type(index_type) -> row_index_type<size_t>;
77 
79 template <simd_index index_type>
80 row_index_type(index_type) -> row_index_type<index_type>;
82 
87 template <typename index_t>
88  requires (std::integral<index_t> || simd_index<index_t>)
89 struct matrix_index
90 {
94  constexpr matrix_index() = default;
95  constexpr matrix_index(matrix_index const &) = default;
96  constexpr matrix_index(matrix_index &&) = default;
97  constexpr matrix_index & operator=(matrix_index const &) = default;
98  constexpr matrix_index & operator=(matrix_index &&) = default;
99  ~matrix_index() = default;
100 
105  constexpr matrix_index(row_index_type<index_t> const row_idx, column_index_type<index_t> const col_idx) noexcept :
106  row{row_idx.get()},
107  col{col_idx.get()}
108  {}
109 
126  template <seqan3::arithmetic scalar_index_t>
127  constexpr matrix_index(row_index_type<scalar_index_t> const row_idx,
128  column_index_type<scalar_index_t> const col_idx) noexcept
129  requires simd_index<index_t>
130  // Note the explicit type conversion is necessary since the scalar type might be of smaller bit size.
131  :
132  row{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(row_idx.get()))},
133  col{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(col_idx.get()))}
134  {}
135 
139  template <std::integral other_index_t>
140  requires (!std::same_as<other_index_t, index_t>)
141  explicit constexpr matrix_index(matrix_index<other_index_t> other) noexcept :
142  row{static_cast<index_t>(other.row)},
143  col{static_cast<index_t>(other.col)}
144  {}
146 
148  template <std::integral first_index_t, std::integral second_index_t>
149  constexpr explicit operator std::pair<first_index_t, second_index_t>() const noexcept
150  {
151  return std::pair{static_cast<first_index_t>(col), static_cast<second_index_t>(row)};
152  }
153 
154  index_t row{};
155  index_t col{};
156 };
157 
163 matrix_index()->matrix_index<std::ptrdiff_t>;
164 
166 template <std::integral row_index_t, std::integral col_index_t>
167  requires std::common_with<row_index_t, col_index_t>
168 matrix_index(row_index_type<row_index_t>, column_index_type<col_index_t>)
169  -> matrix_index<std::common_type_t<row_index_t, col_index_t>>;
170 
172 template <simd_index index_t>
173 matrix_index(row_index_type<index_t>, column_index_type<index_t>) -> matrix_index<index_t>;
175 
178 using matrix_coordinate = matrix_index<size_t>;
179 
184 template <simd_index index_t>
185 using simd_matrix_coordinate = matrix_index<index_t>;
186 
189 using matrix_offset = matrix_index<std::ptrdiff_t>;
190 } // namespace seqan3::detail
Provides algorithms to modify seqan3::simd::simd_type.
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
matrix_index< size_t > matrix_coordinate
A coordinate type to access an element inside of a two-dimensional matrix.
Definition: matrix_coordinate.hpp:178
Provides basic data structure for strong types.
Provides concepts that do not have equivalents in C++20.
Provides seqan3::simd::simd_concept.