SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
19 #include <seqan3/std/concepts>
20 
21 namespace seqan3::detail
22 {
27 template <std::integral index_type>
28 struct column_index_type : detail::strong_type<index_type, column_index_type<index_type>>
29 {
31  using detail::strong_type<index_type, column_index_type<index_type>>::strong_type;
32 };
33 
38 template <std::signed_integral index_type>
40 column_index_type(index_type) -> column_index_type<std::ptrdiff_t>;
41 
43 template <std::unsigned_integral index_type>
44 column_index_type(index_type) -> column_index_type<size_t>;
46 
51 template <std::integral index_type>
52 struct row_index_type : detail::strong_type<index_type, row_index_type<index_type>>
53 {
55  using detail::strong_type<index_type, row_index_type<index_type>>::strong_type;
56 };
57 
62 template <std::signed_integral index_type>
64 row_index_type(index_type) -> row_index_type<std::ptrdiff_t>;
65 
67 template <std::unsigned_integral index_type>
68 row_index_type(index_type) -> row_index_type<size_t>;
70 
73 template <std::integral index_t>
74 struct matrix_index
75 {
79  constexpr matrix_index() = default;
80  constexpr matrix_index(matrix_index const &) = default;
81  constexpr matrix_index(matrix_index &&) = default;
82  constexpr matrix_index & operator=(matrix_index const &) = default;
83  constexpr matrix_index & operator=(matrix_index &&) = default;
84  ~matrix_index() = default;
85 
90  constexpr matrix_index(row_index_type<index_t> const row_idx,
91  column_index_type<index_t> const col_idx) noexcept
92  : row{row_idx.get()}, col{col_idx.get()}
93  {}
94 
98  template <std::integral other_index_t>
102  explicit constexpr matrix_index(matrix_index<other_index_t> other) noexcept
103  : row{static_cast<index_t>(other.row)}, col{static_cast<index_t>(other.col)}
104  {}
106 
108  template <std::integral first_index_t, std::integral second_index_t>
109  constexpr explicit operator std::pair<first_index_t, second_index_t>() const noexcept
110  {
111  return std::pair{static_cast<first_index_t>(col), static_cast<second_index_t>(row)};
112  }
113 
114  index_t row{};
115  index_t col{};
116 };
117 
122 matrix_index() -> matrix_index<std::ptrdiff_t>;
124 
126 template <std::integral row_index_t, std::integral col_index_t>
130 matrix_index(row_index_type<row_index_t>, column_index_type<col_index_t>) ->
131  matrix_index<std::common_type_t<row_index_t, col_index_t>>;
132 
134 
137 using matrix_coordinate = matrix_index<size_t>;
138 
141 using matrix_offset = matrix_index<std::ptrdiff_t>;
142 } // namespace seqan3::detail
std::pair
strong_type.hpp
Provides basic data structure for strong types.
concepts
The Concepts library.
same_as
The concept std::same_as<T, U> is satisfied if and only if T and U denote the same type.
core_language.hpp
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
common_with
The concept std::common_with<T, U> specifies that two types T and U share a common type (as computed ...