This library aims to provide general purpose concepts that are not available in the C++20 concepts library, most notably container concepts. It also provides utilities for writing your own concepts (a
mock_iterator that can mock any iterator category - see bellow).
At the moment, only GCC 10.2 is confirmed to be able to compile all of this library.
Installing with Conan
If you use Conan to manage dependencies, you can get this library from my artifactory.
- Add my artifactory repository to your local Conan install:
conan remote add miso1289 https://miso1289.jfrog.io/artifactory/api/conan/miso1289
- Add the reference to your
- Install the dependency before building:
conan install -b missing $CONAN_DIR, where
CONAN_DIRis your top-level directory (containing your conanfile).
The container concepts are intended to serve as an abstraction for the STL container interfaces, allowing writing constrained generic code that can use any container of some category, both standard and third-party (as long as it provides an STL compliant interface).
While a lot of generic algorithms can do with range and iterator concepts, this is sometimes not enough - for example, how does one write a constrained container adaptor? Let's say you want to implement a priority queue that can use any index-able sequence type with back-insertion to store the heap. Using this library, you could express this as:
template <typename T, more_concepts::random_access_container_of
Seq = std::vector > requires more_concepts::back_growable_container class priority_queue;
General container concepts
container- Satisfied by all well-behaved (not
vector) standard containers.
mutable_container- A container that allows mutable iteration. Satisfied by all standard containers except
sized_container- A container that knows its size. Satisfied by all standard containers except
clearable_container- A container that can be cleared . Satisfied by all standard containers except
reversible_container- A container that allows reverse iteration. Satisfied by all standard containers except
For each of the above, an
_of version is provided (e.g.
reversible_container_of), that also requires the
value_type to be the same as specified.
Sequence container concepts
sequence_container- A mutable container that represents linear ordering of elements (corresponds to the standard
SequenceContainernamed requirement). Provides efficient access to the beginning of the sequence. Satisfied by all standard sequence containers, namely
double_ended_container- A sized and reversible sequence container that provides efficient access to the end of the sequence. Satisfied by all standard sequence containers except
random_access_container- A double-ended sequence container that provides indexed access to elements. Satisfied by
contiguous_container- A random-access sequence container, stored contiguously in memory. Satisfied by
resizable_sequence_container- A clearable double-ended container that allows resizing, range construction and assignment, and insertion / erasure in the middle). Satisfied by
inplace_constructing_sequence_container- Extends the
resizable_sequence_containerinterface with in-place construction. Satisfied by all standard models of
front_growable_container- A sequence container that allows efficient inserting / erasure at the front. Satisfied by
inplace_front_constructing_container- Extends the
front_growable_containerinterface with in-place construction. Satisfied by all standard models of
back_growable_container- A double-ended container that allows efficient inserting / erasure at the back. Satisfied by
inplace_back_constructing_container- Extends the
back_growable_containerinterface with in-place construction. Satisfied by all standard models of
For each sequence container concept, an
_of version is also provided.
Associative container concepts
associative_container- A container that provides fast lookup of objects based on keys. Represents a union of the standard named requirements
UnorderedAssociativeContainer. Satisfied by all standard associative containers.
unique_associative_container- An associative container with unique keys. Satisfied by
multiple_associative_container- An associative container with non-unique keys. Satisfied by
map_container- An associative container representing a key-value mapping. Satisfied by
unique_map_container- A map container with unique keys. Satisfied by
multiple_map_container- A map container with non-unique keys. Satisfied by
For each associative container / map concept,
unordered_ versions are available (e.g.
For each generic (non-map) associative container concept, an
_of version is available.
For each map container concept, an
_of version is available.
Concepts that are simple wrappers over standard type traits:
decayed- Types that are non-reference, non-c-array, non-function or function reference, non-const and non-volatile. Assigning an object of this type to an auto variable preserves the type. Used to constrain the
aggregate- Types that support aggregate initialization.
trivial- Types that can be
memcpy-ied, and don't need any (non-trivial) initialization or destruction.
enum_type- Scoped and unscoped enumeration types.
error_code_enum- Error enum that can be used to construct a
error_condition_enum- Error enum that can be used to construct a
invocable_as- Function types that can be called with
std::invokeusing one or more function signatures. The return type of each signature is only checked for convertibility.
callable_as- Function types that can be called with the function-call operator using one or more function signatures. The return type of each signature must be matched exactly.
hash_function- corresponds to the
Hashstandard named requirement. Used to define the
mock_iterator class template can be used to write concepts that require some operation to accept any iterator of some category.
T- iterator value type.
IteratorCategory- can be one of the standard iterator category tags (e.g.
std::input_iterator_tag). The mock iterator provides the minimal needed interface to satisfy the requested category. E.g. for the input and output iterator categories, a proxy reference type is used instead of a raw reference.
RWCategory- can be one of
const_iterator_tag. Indicates whether the mock iterator should support write access.