SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
concept.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 
18 #include <seqan3/std/concepts>
19 
20 namespace seqan3::detail
21 {
23 // NOTE: this definition should be used for seqan3::simd, but gcc has a bug that it will not fail silently if
24 // simd_t is a pointer to a incomplete type. Furthermore the is_pointer_v should prevent those cases by checking the type
25 // beforehand, but for some reasons the short-circuit semantic of `&&` does not work in this case and gcc still evaluates
26 // the requires clause which in turn triggers the error.
27 //
28 // If this concept is used directly on incomplete types it will produces this compiler error:
29 // error: invalid use of incomplete type ‘struct incomplete::template_type<int>’
30 // requires std::same_as<decltype(a - b), simd_t>;
31 template <typename simd_t>
32 SEQAN3_CONCEPT simd_concept = requires (simd_t a, simd_t b)
33 {
34  typename simd_traits<std::remove_reference_t<simd_t>>::scalar_type;
35  typename simd_traits<std::remove_reference_t<simd_t>>::mask_type;
36  typename simd_traits<std::remove_reference_t<simd_t>>::swizzle_type;
37 
38  // require that static member variables are defined
39  requires std::integral<decltype(simd_traits<std::remove_reference_t<simd_t>>::length)>;
40  requires std::integral<decltype(simd_traits<std::remove_reference_t<simd_t>>::max_length)>;
41 
42  // assume array access that returns a scalar_type type
43  { a[0] } -> typename simd_traits<std::remove_reference_t<simd_t>>::scalar_type;
44 
45  // require comparison operators
46  requires std::same_as<decltype(a == b), typename simd_traits<std::remove_reference_t<simd_t>>::mask_type>;
47  requires std::same_as<decltype(a != b), typename simd_traits<std::remove_reference_t<simd_t>>::mask_type>;
48  requires std::same_as<decltype(a < b), typename simd_traits<std::remove_reference_t<simd_t>>::mask_type>;
49  requires std::same_as<decltype(a > b), typename simd_traits<std::remove_reference_t<simd_t>>::mask_type>;
50  requires std::same_as<decltype(a <= b), typename simd_traits<std::remove_reference_t<simd_t>>::mask_type>;
51  requires std::same_as<decltype(a >= b), typename simd_traits<std::remove_reference_t<simd_t>>::mask_type>;
52 
53  // require arithmetic operators
54  requires std::same_as<decltype(a + b), std::remove_reference_t<simd_t>>;
55  requires std::same_as<decltype(a - b), std::remove_reference_t<simd_t>>;
56  requires std::same_as<decltype(a * b), std::remove_reference_t<simd_t>>;
57  requires std::same_as<decltype(a / b), std::remove_reference_t<simd_t>>;
58  requires std::same_as<decltype(a += b), std::remove_reference_t<simd_t> &>;
59  requires std::same_as<decltype(a -= b), std::remove_reference_t<simd_t> &>;
60  requires std::same_as<decltype(a *= b), std::remove_reference_t<simd_t> &>;
61  requires std::same_as<decltype(a /= b), std::remove_reference_t<simd_t> &>;
62 };
64 
65 } // namespace seqan3::detail
66 
67 namespace seqan3
68 {
69 
70 inline namespace simd
71 {
72 
86 template <typename simd_t>
88 SEQAN3_CONCEPT simd_concept = !std::is_pointer_v<std::decay_t<simd_t>> && detail::simd_concept<simd_t>;
90 
91 } // inline namespace simd
92 
93 } // namespace seqan3
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.
simd_traits.hpp
Provides seqan3::simd::simd_traits.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
std::remove_reference_t
integral
The concept integral is satisfied if and only if T is an integral type.