SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
affine_cell_proxy.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 <tuple>
16 #include <type_traits>
17 
21 
22 namespace seqan3::detail
23 {
24 
29 template <typename t>
31 SEQAN3_CONCEPT arithmetic_or_simd = arithmetic<t> || simd_concept<t>;
33 
44 template <typename t>
46 SEQAN3_CONCEPT affine_score_cell = tuple_like<t> &&
47  std::tuple_size_v<t> == 3 &&
48  arithmetic_or_simd<std::remove_reference_t<std::tuple_element_t<0, t>>> &&
49  arithmetic_or_simd<std::remove_reference_t<std::tuple_element_t<1, t>>> &&
50  arithmetic_or_simd<std::remove_reference_t<std::tuple_element_t<2, t>>>;
52 
65 template <affine_score_cell tuple_t>
67  requires (std::tuple_size_v<tuple_t> == 3)
69 class affine_cell_proxy : public tuple_t
70 {
71 public:
75  affine_cell_proxy()= default;
76  affine_cell_proxy(affine_cell_proxy const &) = default;
77  affine_cell_proxy(affine_cell_proxy &&) = default;
78  affine_cell_proxy & operator=(affine_cell_proxy const &) = default;
79  affine_cell_proxy & operator=(affine_cell_proxy &&) = default;
80  ~affine_cell_proxy() = default;
81 
82  // Inherit the tuple constructors and assignment.
83  using tuple_t::tuple_t;
84  using tuple_t::operator=;
86 
91  decltype(auto) best_score() & noexcept { return get_score_impl<0>(*this); }
94  decltype(auto) best_score() const & noexcept { return get_score_impl<0>(*this); }
96  decltype(auto) best_score() && noexcept { return get_score_impl<0>(std::move(*this)); }
98  decltype(auto) best_score() const && noexcept
99  { //Unfortunately gcc7 does not preserve the const && type: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94967
100  using return_t = std::tuple_element_t<0, tuple_t>;
101  return static_cast<return_t const &&>(get_score_impl<0>(std::move(*this)));
102  }
103 
105  decltype(auto) horizontal_score() & noexcept { return get_score_impl<1>(*this); }
107  decltype(auto) horizontal_score() const & noexcept { return get_score_impl<1>(*this); }
109  decltype(auto) horizontal_score() && noexcept { return get_score_impl<1>(std::move(*this)); }
111  decltype(auto) horizontal_score() const && noexcept
112  { //Unfortunately gcc7 does not preserve the const && type: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94967
113  using return_t = std::tuple_element_t<1, tuple_t>;
114  return static_cast<return_t const &&>(get_score_impl<1>(std::move(*this)));
115  }
116 
118  decltype(auto) vertical_score() & noexcept { return get_score_impl<2>(*this); }
120  decltype(auto) vertical_score() const & noexcept { return get_score_impl<2>(*this); }
122  decltype(auto) vertical_score() && noexcept { return get_score_impl<2>(std::move(*this)); }
124  decltype(auto) vertical_score() const && noexcept
125  { //Unfortunately gcc7 does not preserve the const && type: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94967
126  using return_t = std::tuple_element_t<2, tuple_t>;
127  return static_cast<return_t const &&>(get_score_impl<2>(std::move(*this)));
128  }
130 
131 private:
140  template <size_t index, typename this_t>
142  requires (index < 3)
144  static constexpr decltype(auto) get_score_impl(this_t && me) noexcept
145  {
146  using std::get;
147 
148  return get<index>(std::forward<this_t>(me));
149  }
150 };
151 } // namespace seqan3::detail
152 
153 namespace std
154 {
156 template <typename tuple_t>
157 struct tuple_size<seqan3::detail::affine_cell_proxy<tuple_t>> : tuple_size<tuple_t>
158 {};
159 
160 template <size_t index, typename tuple_t>
161 struct tuple_element<index, seqan3::detail::affine_cell_proxy<tuple_t>> : tuple_element<index, tuple_t>
162 {};
164 } // namespace std
tuple
seqan3::views::get
auto const get
A view calling std::get on each element in a range.
Definition: get.hpp:65
concept.hpp
Provides seqan3::simd::simd_concept.
tuple_utility.hpp
Provides utility functions for tuple like interfaces.
seqan3::views::move
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
core_language.hpp
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
tuple_like
Whether a type behaves like a tuple.
std
SeqAn specific customisations in the standard namespace.
arithmetic
A type that satisfies std::is_arithmetic_v<t>.