![]() |
MySQL 9.6.0
Source Code Documentation
|
Code documentation: Meta.
This library contains generic features related to meta-programming, i.e., algorithms executed at compile-time, including concepts, type predicates, and metafunctions (
Other libraries may contain meta-programming utilities related to functions or types defined in that library; this library is for "pure" meta-programming utilities.
Currently, it contains the following:
not_decayed.h: concept used to protect a constructor taking forwarding reference arguments from being used as copy constructor.
This is intended to be used in constructors taking (variadic) forwarding references, like:
template <class... Args_t> requires Not_decayed<Type, Args...> Type::Type(Args_t &&...);
When a Type object is copied, and this constructor would not have the constraint, this constructor could be a better match than the copy constructor Type::Type(const Type &), according to the compiler's overload resolution rules. The reason is that the copy constructor requires a const argument, whereas the forwarding constructor accepts non-const arguments; thus if you copy a non-const object the forwarding constructor is preferred. The constraint prevents that this constructor is invoked with a single argument of type Type, Type &, const Type &, or Type &&.
We use the following terminology.
metafunctions. A metafunction is like a "function" (in a broad sense) that takes a type as argument and returns a type. In C++ they are typically defined with using directives taking template arguments. Example:
concepts, the C++20 feature. A concept is like a "function" that takes a type as argument and returns a boolean value. Example:
type predicates. A type predicate is a struct that derives from std::integral_constant, and usually even std::bool_constant. Its purpose is the same as that of a concept: to take a type as argument and return a boolean value. See below for a comparison of the two tools. Example:
Although concepts and type predicates have exactly the same purpose, both these tools are needed, because C++ puts different limitations on type predicates and concepts:
concepts, but not type predicates, are allowed in the following syntactic contexts:
type predicates, but not concepts, can be passed as template arguments. Therefore, if a generic metafunction executes an algorithm, and a parameter of that algorithm is a function on types, then that parameter can be expressed as a type constraint, but not as a concept: