SeqAn3
concept.hpp
Go to the documentation of this file.
1 // ============================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ============================================================================
4 //
5 // Copyright (c) 2006-2018, Knut Reinert & Freie Universitaet Berlin
6 // Copyright (c) 2016-2018, Knut Reinert & MPI Molekulare Genetik
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
25 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 // DAMAGE.
32 //
33 // ============================================================================
34 
40 #pragma once
41 
42 #include <iostream>
43 
47 #include <seqan3/alphabet/adaptation/pre.hpp>
50 #include <seqan3/std/concepts>
51 
52 namespace seqan3
53 {
54 
55 // ------------------------------------------------------------------
56 // semi_alphabet_concept
57 // ------------------------------------------------------------------
58 
92 //TODO(rrahn): Change to template <typename t2, typename t = std::remove_reference_t<t2>>
94 // in order to get rid of the remove_reference_t within the concept, after the ICE
95 // get's fixed. See issue #228
96 template <typename t>
97 concept semi_alphabet_concept = std::Regular<std::remove_reference_t<t>> &&
99  requires (t t1, t t2)
100 {
101 
102  // static data members
103  alphabet_size<std::remove_reference_t<t>>::value;
104  alphabet_size_v<std::remove_reference_t<t>>;
105 
106  // conversion to rank
107  { to_rank(t1) } -> underlying_rank_t<std::remove_reference_t<t>>;
108 
109  // assignment from rank
110  { assign_rank(t1, 0) } -> std::remove_reference_t<t> &;
111  { assign_rank(std::remove_reference_t<t>{}, 0) } -> std::remove_reference_t<t> &&;
112 };
114 
115 // ------------------------------------------------------------------
116 // alphabet_concept
117 // ------------------------------------------------------------------
118 
144 //TODO(rrahn): Change to template <typename t2, typename t = std::remove_reference_t<t2>>
146 // in order to get rid of the remove_reference_t within the concept, after the ICE
147 // get's fixed. See issue #228
148 template <typename t>
149 concept alphabet_concept = semi_alphabet_concept<t> && requires (t t1, t t2)
150 {
151  // conversion to char
152  { to_char(t1) } -> underlying_char_t<std::remove_reference_t<t>>;
153 
154  // assignment from char
155  { assign_char(t1, 0) } -> std::remove_reference_t<t> &;
156  { assign_char(std::remove_reference_t<t>{}, 0) } -> std::remove_reference_t<t> &&;
157 };
159 
160 // ------------------------------------------------------------------
161 // serialisation
162 // ------------------------------------------------------------------
163 
183 template <cereal_output_archive_concept archive_t, semi_alphabet_concept alphabet_t>
184 underlying_rank_t<alphabet_t> CEREAL_SAVE_MINIMAL_FUNCTION_NAME(archive_t const &, alphabet_t const & l)
185 {
186  return to_rank(l);
187 }
188 
202 template <cereal_input_archive_concept archive_t, typename wrapped_alphabet_t>
203 void CEREAL_LOAD_MINIMAL_FUNCTION_NAME(archive_t const &,
204  wrapped_alphabet_t && l,
205  underlying_rank_t<detail::strip_cereal_wrapper_t<wrapped_alphabet_t>> const & r)
206  requires semi_alphabet_concept<detail::strip_cereal_wrapper_t<wrapped_alphabet_t>>
207 {
208  assign_rank(static_cast<detail::strip_cereal_wrapper_t<wrapped_alphabet_t>&&>(l), r);
209 }
214 } // namespace seqan3
215 
216 namespace seqan3::detail
217 {
218 // ------------------------------------------------------------------
219 // constexpr_semi_alphabet_concept
220 // ------------------------------------------------------------------
221 
235 template <typename t>
237 concept constexpr_semi_alphabet_concept = semi_alphabet_concept<t> && requires
238 {
239  // currently only tests rvalue interfaces, because we have no constexpr values in this scope to get references to
240  requires SEQAN3_IS_CONSTEXPR(to_rank(std::remove_reference_t<t>{}));
241  requires SEQAN3_IS_CONSTEXPR(assign_rank(std::remove_reference_t<t>{}, 0));
242 };
244 
245 // ------------------------------------------------------------------
246 // constexpr_alphabet_concept
247 // ------------------------------------------------------------------
248 
263 template <typename t>
265 concept constexpr_alphabet_concept = constexpr_semi_alphabet_concept<t> &&
266  alphabet_concept<t> &&
267  requires
268 {
269  // currently only tests rvalue interfaces, because we have no constexpr values in this scope to get references to
270  requires SEQAN3_IS_CONSTEXPR(to_char(std::remove_reference_t<t>{}));
271  requires SEQAN3_IS_CONSTEXPR(assign_char(std::remove_reference_t<t>{},
272  underlying_char_t<std::remove_reference_t<t>>{}));
273 };
275 
276 } // namespace seqan3::detail
277 
Provides concepts for core language types and relations that don&#39;t have concepts in C++20 (yet)...
Free function/metafunction wrappers for alphabets with member functions/types.
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
seqan3::alphabet_concept metafunction base classes.
Subsumes std::Semiregular and std::EqualityComparable.
constexpr alphabet_type & assign_rank(alphabet_type &alph, underlying_rank_t< alphabet_type > const rank) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::assign_rank() that delegates to a member function...
Definition: member_exposure.hpp:110
Provides various metafunctions for use on functions.
The Concepts library.
Adaptions of concepts from the Cereal library.
Definition: aligned_sequence_concept.hpp:288
#define SEQAN3_IS_CONSTEXPR(...)
Returns true if the expression passed to this macro can be evaluated at compile time, false otherwise.
Definition: function.hpp:67
constexpr alphabet_type & assign_char(alphabet_type &alph, underlying_char_t< alphabet_type > const chr) requires requires(alphabet_type alph)
Implementation of seqan3::alphabet_concept::assign_char() that delegates to a member function...
Definition: member_exposure.hpp:178
Provides overloads for std::hash.
constexpr underlying_rank_t< alphabet_type > to_rank(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::semi_alphabet_concept::to_rank() that delegates to a member function...
Definition: member_exposure.hpp:97
constexpr underlying_char_t< alphabet_type > to_char(alphabet_type const alph) requires requires(alphabet_type alph)
Implementation of seqan3::alphabet_concept::to_char() that delegates to a member function.
Definition: member_exposure.hpp:165
Requires std::EqualityComparable and all remaing comparison operators (<, <=, >, >=).