Utility classes for definining and using concepts lite in C++11. More...
#include <atria/estd/type_traits.hpp>
#include <atria/meta/utils.hpp>
#include <atria/meta/pack.hpp>
#include <ableton/build_system/Warnings.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply.hpp>
#include <algorithm>
Go to the source code of this file.
Classes | |
struct | models< ConceptSig, Enable > |
Returns whether a concept signature ConceptSig is satisfied. More... | |
struct | models< ConceptSpecT(Ts...), estd::void_t< decltype(std::declval< ConceptSpecT >().requires_( std::declval< Ts >()...)) > > |
struct | models_< ConceptSpecT, T > |
struct | if_any< T, Mfs > |
Metafunction that given a type T and a one or more of MPL metafunction classes Mfs that boolean metafunctions, returns whether any of these metafunctios Mfs returns true when applied with T. More... | |
struct | if_any< T, Mf, Mfs... > |
struct | if_any< T, Mf > |
Namespaces | |
atria | |
C++ amazing templates and reusable implementations awesomeness. | |
atria::meta | |
Metaprogramming tools, including some Booost.MPL adaptors and concept checking facilities. | |
Macros | |
#define | ABL_CONCEPT constexpr |
Macro for future-proof concept-lite like concepts. More... | |
#define | ABL_CONCEPT_SPEC(concept_name) |
Helper macro to define concept-lite style concepts. More... | |
#define | ABL_ASSERT_CONCEPT(concept, ...) |
Macro to check, at compile-time, that a concept is satisfied. More... | |
#define | ABL_ASSERT_NOT_CONCEPT(concept, ...) |
Macro to check that a concept is not satisfied by some types. More... | |
Typedefs | |
template<bool Requirement> | |
using | require = estd::enable_if_t< Requirement, int > |
Utility to define concepts in terms of other concepts or other kinds boolean requirements. More... | |
template<typename T , typename... Mfs> | |
using | require_any = estd::enable_if_t< if_any< T, Mfs... >::type::value, int > |
Like require, but based on the semantics of if_any . More... | |
Functions | |
constexpr bool | all () |
Returns true if all the passed in values are true. More... | |
template<typename T , typename... Ts> | |
constexpr bool | all (T x, Ts...xs) |
template<typename... Ts> | |
constexpr bool | valid () |
Concept that is always satisfied by the type or family of types that is passed to it. More... | |
template<typename... Ts> | |
void | expressions (Ts &&...) |
Allows to validate a sequence of expressions in a single decltype. More... | |
template<typename ConceptSig > | |
constexpr bool | check () |
Like models, but fails at compile-time when the specification is not met. More... | |
template<typename ConceptSpecT , typename... Ts> | |
constexpr bool | check (pack< ConceptSpecT(Ts...)>) |
template<template< typename... >class ConceptSpecT, typename... Ts> | |
constexpr bool | check (pack< ConceptSpecT< Ts... > >) |
Detailed Description
Utility classes for definining and using concepts lite in C++11.
C++14 introduces the notion of Concepts Lite. Concepts, as in Concepts Lite, are just a constexpr
nullary function templated over T
, that returns a bool
indicating whether T
satisfies the concept.
In this sense, require
as defined in the new standard is a glorified enable_if
. Also, these concepts can already be defined in C++11. The problem is, in C++11, constexpr functions are so limited that some of these functions are hard to define. This namespace provides some utilities that make concepts easier to define and use.
Here are some references where most of these techniques where borrowed from:
- The C++ language 4th edition. (Stroustoup)
- Concepts lite: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3580.pdf
- The origin library: https://code.google.com/p/origin/
- Concept checking in C++11 http://ericniebler.com/2013/11/23/concept-checking-in-c11/
Definition in file concept.hpp.
Macro Definition Documentation
#define ABL_ASSERT_CONCEPT | ( | concept, | |
... | |||
) |
Macro to check, at compile-time, that a concept is satisfied.
It generates a static assertion that checks the given concept for the given set of types.
Definition at line 290 of file concept.hpp.
#define ABL_ASSERT_NOT_CONCEPT | ( | concept, | |
... | |||
) |
Macro to check that a concept is not satisfied by some types.
Opposite of ABL_ASSERT_CONCEPT
Definition at line 301 of file concept.hpp.
#define ABL_CONCEPT constexpr |
Macro for future-proof concept-lite like concepts.
In the future, it will expand to the concept
keyword, for now it expands to constexpr
. Example:
Definition at line 211 of file concept.hpp.
#define ABL_CONCEPT_SPEC | ( | concept_name | ) |
Helper macro to define concept-lite style concepts.
The macro defines:
- A concept-lite like concept named
{concept_name}
. In pre-C++17 compilers this is just aconstexpr
function template that returnsbool
. - It opens the definition of a type
{concept_name}_spec
that is a meant to be a concept spectification.
Example:
- See also
- models
Definition at line 243 of file concept.hpp.