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 <initializer_list>
16 #include <iterator>
17 #include <type_traits>
18 
19 // remove if is_basic_string is not needed anymore
20 #include <string>
21 
22 #include <seqan3/std/iterator>
23 #include <seqan3/std/concepts>
24 
25 // TODO:
26 // * remove is_basic_string
27 // * remove #include <string> in this file
28 // once the gcc bug [1] was fixed AND we require at least a gcc version which
29 // contains this fix
30 //
31 // [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83328
32 namespace seqan3::detail
33 {
35 
38 template <typename basic_string_t>
39 struct is_basic_string : std::false_type
40 {};
41 
44 template <typename value_t, typename traits_t, typename allocator_t>
45 struct is_basic_string<std::basic_string<value_t, traits_t, allocator_t>> : std::true_type
46 {};
47 
50 template <typename basic_string_t>
51 constexpr bool is_basic_string_v = is_basic_string<basic_string_t>::value;
52 
54 
55 } // seqan3::detail
56 
57 namespace seqan3
58 {
59 
77 template <typename type>
79 SEQAN3_CONCEPT container = requires (type val, type val2, type const cval, typename type::iterator it)
80 {
81  // member types
82  typename type::value_type;
83  typename type::reference;
84  typename type::const_reference;
85 /*
86  typename type::iterator;
87  requires std::forward_iterator<typename type::iterator>;
88  { it } -> typename type::const_iterator; // NOTE check whether iterator is const convertible
89 
90  typename type::const_iterator;
91  requires std::forward_iterator<typename type::const_iterator>;
92 
93  typename type::difference_type;
94  typename type::size_type;
95  requires std::is_same_v<
96  typename type::difference_type,
97  typename std::iterator_traits<typename type::iterator>::difference_type
98  >;
99  requires std::is_same_v<
100  typename std::iterator_traits<typename type::iterator>::difference_type,
101  typename std::iterator_traits<typename type::const_iterator>::difference_type
102  >;
103 */
104  // methods and operator
105  { type{} } -> type; // default constructor
106  { type{type{}} } -> type; // copy/move constructor
107  { val = val2 } -> type &; // assignment
108  { (&val)->~type() }; // destructor
109 
110  { val.begin() } -> typename type::iterator;
111  { val.end() } -> typename type::iterator;
112  { cval.begin() } -> typename type::const_iterator;
113  { cval.end() } -> typename type::const_iterator;
114  { val.cbegin() } -> typename type::const_iterator;
115  { val.cend() } -> typename type::const_iterator;
116 
118 
119  { val.swap(val2) } -> void;
120  { swap(val, val2) } -> void;
121  { std::swap(val, val2) } -> void;
122 
123  { val.size() } -> typename type::size_type;
124  { val.max_size() } -> typename type::size_type;
125  { val.empty() } -> bool;
126 };
128 
141 template <typename type>
143 SEQAN3_CONCEPT sequence_container = requires (type val, type val2, type const cval)
144 {
145  requires container<type>;
146 
147  // construction
148  { type{typename type::size_type{}, typename type::value_type{}} };
149  { type{val2.begin(), val2.end()} }; // NOTE that this could be any input iterator:
152 
153  // assignment NOTE return type is type & for std::string and void for other stl containers:
154  { val.assign(val2.begin(), val2.end()) };
156  { val.assign(typename type::size_type{}, typename type::value_type{}) };
157 
158  // modify container
159  // TODO: how do you model this?
160  // { val.emplace(typename type::const_iterator{}, ? } -> typename type::iterator;
161  { val.insert(val.cbegin(), val2.front()) } -> typename type::iterator;
162  { val.insert(val.cbegin(), typename type::value_type{}) } -> typename type::iterator;
163  { val.insert(val.cbegin(), typename type::size_type{}, typename type::value_type{})} -> typename type::iterator;
164  { val.insert(val.cbegin(), val2.begin(), val2.end()) } -> typename type::iterator;
165  requires detail::is_basic_string_v<type> || requires(type val)
166  {
167  // TODO this function is not defined on strings (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83328)
168  { val.insert(val.cbegin(), std::initializer_list<typename type::value_type>{}) } -> typename type::iterator;
169  };
170 
171  { val.erase(val.cbegin()) } -> typename type::iterator;
172  { val.erase(val.cbegin(), val.cend()) } -> typename type::iterator;
173 
174  { val.push_back(val.front()) } -> void;
175  { val.push_back(typename type::value_type{}) } -> void;
176  { val.pop_back() } -> void;
177  { val.clear() } -> void;
178 
179  // access container
180  { val.front() } -> typename type::reference;
181  { cval.front() } -> typename type::const_reference;
182  { val.back() } -> typename type::reference;
183  { cval.back() } -> typename type::const_reference;
184 };
186 
201 template <typename type>
203 SEQAN3_CONCEPT random_access_container = requires (type val)
204 {
205  requires sequence_container<type>;
206 
207  // access container
208  { val[0] } -> typename type::reference;
209  { val.at(0) } -> typename type::reference;
210 
211  // modify container
212  { val.resize(0) } -> void;
213  { val.resize(0, typename type::value_type{}) } -> void;
214 };
216 
227 template <typename type>
229 SEQAN3_CONCEPT reservible_container = requires (type val)
230 {
232 
233  { val.capacity() } -> typename type::size_type;
234  { val.reserve(0) } -> void;
235  { val.shrink_to_fit() } -> void;
236 };
238 
240 
241 } // namespace seqan3
reservible_container
A more refined container concept than seqan3::random_access_container.
std::false_type
sequence_container
A more refined container concept than seqan3::container.
iterator
Provides C++20 additions to the <iterator> header.
concepts
The Concepts library.
seqan3
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:36
std::swap
T swap(T... args)
container
The (most general) container concept as defined by the standard library.
std
SeqAn specific customisations in the standard namespace.
equality_comparable
The same as std::weakly_equality_comparable_with<t,t>.
random_access_container
A more refined container concept than seqan3::sequence_container.
initializer_list
string