SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
matrix_coordinate.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, 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 <type_traits>
16 
21 #include <seqan3/std/concepts>
22 
23 namespace seqan3::detail
24 {
29 template <typename index_type>
31  requires (std::integral<index_type> || simd_index<index_type>)
33 struct column_index_type : detail::strong_type<index_type, column_index_type<index_type>>
34 {
36  using detail::strong_type<index_type, column_index_type<index_type>>::strong_type;
37 };
38 
43 template <std::signed_integral index_type>
45 column_index_type(index_type) -> column_index_type<std::ptrdiff_t>;
46 
48 template <std::unsigned_integral index_type>
49 column_index_type(index_type) -> column_index_type<size_t>;
50 
52 template <simd_index index_type>
53 column_index_type(index_type) -> column_index_type<index_type>;
55 
60 template <typename index_type>
62  requires (std::integral<index_type> || simd_index<index_type>)
64 struct row_index_type : detail::strong_type<index_type, row_index_type<index_type>>
65 {
67  using detail::strong_type<index_type, row_index_type<index_type>>::strong_type;
68 };
69 
74 template <std::signed_integral index_type>
76 row_index_type(index_type) -> row_index_type<std::ptrdiff_t>;
77 
79 template <std::unsigned_integral index_type>
80 row_index_type(index_type) -> row_index_type<size_t>;
81 
83 template <simd_index index_type>
84 row_index_type(index_type) -> row_index_type<index_type>;
86 
91 template <typename index_t>
93  requires (std::integral<index_t> || simd_index<index_t>)
95 struct matrix_index
96 {
100  constexpr matrix_index() = default;
101  constexpr matrix_index(matrix_index const &) = default;
102  constexpr matrix_index(matrix_index &&) = default;
103  constexpr matrix_index & operator=(matrix_index const &) = default;
104  constexpr matrix_index & operator=(matrix_index &&) = default;
105  ~matrix_index() = default;
106 
111  constexpr matrix_index(row_index_type<index_t> const row_idx, column_index_type<index_t> const col_idx) noexcept :
112  row{row_idx.get()},
113  col{col_idx.get()}
114  {}
115 
132  template <seqan3::arithmetic scalar_index_t>
133  constexpr matrix_index(row_index_type<scalar_index_t> const row_idx,
134  column_index_type<scalar_index_t> const col_idx) noexcept
136  requires simd_index<index_t>
138  // Note the explicit type conversion is necessary since the scalar type might be of smaller bit size.
139  : row{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(row_idx.get()))},
140  col{simd::fill<index_t>(static_cast<typename simd_traits<index_t>::scalar_type>(col_idx.get()))}
141  {}
142 
146  template <std::integral other_index_t>
148  requires (!std::same_as<other_index_t, index_t>)
150  explicit constexpr matrix_index(matrix_index<other_index_t> other) noexcept
151  : row{static_cast<index_t>(other.row)}, col{static_cast<index_t>(other.col)}
152  {}
154 
156  template <std::integral first_index_t, std::integral second_index_t>
157  constexpr explicit operator std::pair<first_index_t, second_index_t>() const noexcept
158  {
159  return std::pair{static_cast<first_index_t>(col), static_cast<second_index_t>(row)};
160  }
161 
162  index_t row{};
163  index_t col{};
164 };
165 
170 matrix_index() -> matrix_index<std::ptrdiff_t>;
172 
174 template <std::integral row_index_t, std::integral col_index_t>
176  requires std::common_with<row_index_t, col_index_t>
178 matrix_index(row_index_type<row_index_t>, column_index_type<col_index_t>) ->
179  matrix_index<std::common_type_t<row_index_t, col_index_t>>;
180 
182 template <simd_index index_t>
183 matrix_index(row_index_type<index_t>, column_index_type<index_t>) -> matrix_index<index_t>;
185 
188 using matrix_coordinate = matrix_index<size_t>;
189 
194 template <simd_index index_t>
195 using simd_matrix_coordinate = matrix_index<index_t>;
196 
199 using matrix_offset = matrix_index<std::ptrdiff_t>;
200 } // namespace seqan3::detail
std::pair
strong_type.hpp
Provides basic data structure for strong types.
concept.hpp
Provides seqan3::simd::simd_concept.
concepts
The Concepts library.
simd_algorithm.hpp
Provides algorithms to modify seqan3::simd::simd_type.
core_language.hpp
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).