All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Concepts module

Provides an interface for concept checking. More...

Modules

 Basic concepts submodule
 Concepts involving constructibility and operational semantics.
 
 Container concepts submodule
 Concepts involving the standard C++ containers.
 
 Function concepts submodule
 Concepts involving functions.
 
 Iterator concepts submodule
 Concepts involving iterators.
 

Functions

template<typename T , template< typename...> class... Concepts>
constexpr bool gears::concepts::require ()
 Asserts that a type meets concepts provided. More...
 

Detailed Description

This module is the basic implementation of Concepts that were supposed to appear in C++11 but didn't make it due to time constraints. It doesn't support axioms, concept maps, or any of the fancy stuff but provides enough syntactic sugar for the SFINAE part of the concepts proposal.

Concepts are split into two categories, Unary and Binary. A Unary Concept is defined as a concept that takes in a single type. A Binary Concept is a concept that takes in two types. Most of the time the second type is optional, this depends on the Concept. Sometimes a concept is not part of these categories, this makes the concept uncategorised. An example of this is Constructible.

Just like the Concepts themselves are split into different categories, the Concepts module itself is split into different categories which include:

The usage of Concepts is simple, most of which needs one function to assert your concepts.

Example:

#include <gears/concepts.hpp>
#include <vector>
using namespace gears::concepts;
template<typename Cont, typename T>
void compare_and_insert(Cont& c, const T& first, const T& second) {
// first < second must be well defined.
require<T, LessThanComparable>();
// Cont must be a sequence container
require<Cont, SequenceContainer>();
if(first < second) {
c.push_back(first);
}
else {
c.push_back(second);
}
}
int main() {
std::vector<int> v = {1,2,3,4,5,6,7,8,9,10};
compare_and_insert(v, 11, 12);
}

Function Documentation

template<typename T , template< typename...> class... Concepts>
constexpr bool gears::concepts::require ( )

The place for requires is best inside functions rather than classes. As this function returns a boolean, it isn't possible to put it in its own line for template classes. For example, the following won't work:

template<typename T>
struct my_type {
requires<T, Assignable>();
};

This is because this function returns a boolean. Consider using the Require statement instead:

template<typename T, typename = Require<Assignable<T>>
struct my_type {};
Template Parameters
TType to check concepts for
Concepts...Unary concepts to assert.
Returns
true, this value should probably be ignored as it is only there for constexpr status.

Definition at line 98 of file concepts/alias.hpp.