BioC++ core-0.7.0
The Modern C++ libraries for Bioinformatics.
 
Loading...
Searching...
No Matches
concept.hpp
Go to the documentation of this file.
1// -----------------------------------------------------------------------------------------------------
2// Copyright (c) 2022 deCODE Genetics
3// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7// -----------------------------------------------------------------------------------------------------
8
14#pragma once
15
16#include <initializer_list>
17#include <iterator>
18#include <type_traits>
19
20// remove if is_basic_string is not needed anymore
21#include <concepts>
22#include <iterator>
23#include <string>
24
25#include <bio/core.hpp>
26
27namespace bio::ranges::detail
28{
45template <typename type>
46concept container = requires(type val, type val2, type const cval, typename type::iterator it) {
47 // member types
48 typename type::value_type;
49 typename type::reference;
50 typename type::const_reference;
51 /*
52 typename type::iterator;
53 requires std::forward_iterator<typename type::iterator>;
54 // NOTE check whether iterator is const convertible
55 { it } -> std::same_as<typename type::const_iterator>;
56
57 typename type::const_iterator;
58 requires std::forward_iterator<typename type::const_iterator>;
59
60 typename type::difference_type;
61 typename type::size_type;
62 requires std::is_same_v<
63 typename type::difference_type,
64 typename std::iterator_traits<typename type::iterator>::difference_type
65 >;
66 requires std::is_same_v<
67 typename std::iterator_traits<typename type::iterator>::difference_type,
68 typename std::iterator_traits<typename type::const_iterator>::difference_type
69 >;
70*/
71
72 // clang-format off
73 // methods and operator
74 { type{} } -> std::same_as<type>; // default constructor
75 { type{type{}} } -> std::same_as<type>; // copy/move constructor
76 { val = val2 } -> std::same_as<type &>; // assignment
77 { (&val)->~type() }; // destructor
78
79 { val.begin() } -> std::same_as<typename type::iterator>;
80 { val.end() } -> std::same_as<typename type::iterator>;
81 { cval.begin() } -> std::same_as<typename type::const_iterator>;
82 { cval.end() } -> std::same_as<typename type::const_iterator>;
83 { val.cbegin() } -> std::same_as<typename type::const_iterator>;
84 { val.cend() } -> std::same_as<typename type::const_iterator>;
85
86 requires !std::equality_comparable<typename type::value_type> || std::equality_comparable<type>;
87
88 { val.swap(val2) } -> std::same_as<void>;
89 { swap(val, val2) } -> std::same_as<void>;
90 { std::swap(val, val2) } -> std::same_as<void>;
91
92 { val.size() } -> std::same_as<typename type::size_type>;
93 { val.max_size() } -> std::same_as<typename type::size_type>;
94 { val.empty() } -> std::same_as<bool>;
95 // clang-format on
96};
97
109template <typename type>
110concept sequence_container = requires(type val, type val2, type const cval) {
111 requires container<type>;
112
113 // clang-format off
114 // construction
115 { type{typename type::size_type{}, typename type::value_type{}} };
116 { type{val2.begin(), val2.end()} }; // NOTE that this could be any input iterator:
118 { val = std::initializer_list<typename type::value_type>{} } -> std::same_as<type &>;
119
120 // assignment NOTE return type is type & for std::string and void for other stl containers:
121 { val.assign(val2.begin(), val2.end()) };
123 { val.assign(typename type::size_type{}, typename type::value_type{}) };
124
125 // modify container
126 // TODO: how do you model this?
127 // BIOCPP_RETURN_TYPE_CONSTRAINT(val.emplace(typename type::const_iterator{}, ?),
128 // std::same_as, typename type::iterator);
129 { val.insert(val.cbegin(), val2.front()) } -> std::same_as<typename type::iterator>;
130 { val.insert(val.cbegin(), typename type::value_type{}) } -> std::same_as<typename type::iterator>;
131 { val.insert(val.cbegin(), typename type::size_type{}, typename type::value_type{}) }
132 -> std::same_as<typename type::iterator>;
133 { val.insert(val.cbegin(), val2.begin(), val2.end()) } -> std::same_as<typename type::iterator>;
134 { val.insert(val.cbegin(), std::initializer_list<typename type::value_type>{}) } ->
135 std::same_as<typename type::iterator>;
136
137 { val.erase(val.cbegin()) } -> std::same_as<typename type::iterator>;
138 { val.erase(val.cbegin(), val.cend()) } -> std::same_as<typename type::iterator>;
139
140 { val.push_back(val.front()) } -> std::same_as<void>;
141 { val.push_back(typename type::value_type{}) } -> std::same_as<void>;
142 { val.pop_back() } -> std::same_as<void>;
143 { val.clear() } -> std::same_as<void>;
144
145 // access container
146 { val.front() } -> std::same_as<typename type::reference>;
147 { cval.front() } -> std::same_as<typename type::const_reference>;
148 { val.back() } -> std::same_as<typename type::reference>;
149 { cval.back() } -> std::same_as<typename type::const_reference>;
150 // clang-format on
151};
152
166template <typename type>
167concept random_access_container = requires(type val) {
168 requires sequence_container<type>;
169
170 // clang-format off
171 // access container
172 { val[0] } -> std::same_as<typename type::reference>;
173 { val.at(0) } -> std::same_as<typename type::reference>;
174
175 // modify container
176 { val.resize(0) } -> std::same_as<void>;
177 { val.resize(0, typename type::value_type{}) } -> std::same_as<void>;
178 // clang-format on
179};
180
190template <typename type>
191concept reservible_container = requires(type val) {
192 requires random_access_container<type>;
193
194 // clang-format off
195 { val.capacity() } -> std::same_as<typename type::size_type>;
196 { val.reserve(0) } -> std::same_as<void>;
197 { val.shrink_to_fit() } -> std::same_as<void>;
198 // clang-format on
199};
200
202
203} // namespace bio::ranges::detail
Provides platform and dependency checks.
T swap(T... args)