mirror of
https://github.com/boostorg/core.git
synced 2025-11-29 22:00:17 +01:00
Introduces enable_if_type
enable_if_type allow to perform SFINAE check on the existence of a dependent type. It has been used here and there in various boost library but it's useful enough to warrant an autonomous existence.
This commit is contained in:
@@ -304,6 +304,26 @@ depends on the template arguments of the class. Note that
|
||||
again, the second argument to `enable_if` is not needed; the
|
||||
default (`void`) is the correct value.
|
||||
|
||||
The `enable_if_type` template is usable this scenario but instead of
|
||||
using a type traits to enable or disable a specialization, it use a
|
||||
SFINAE context to check for the existence of a dependent type inside
|
||||
its parameter. For example, the following structure extracts a dependent
|
||||
`value_type` from T if and only if `T::value_type` exists.
|
||||
|
||||
``
|
||||
template <class T, class Enable = void>
|
||||
class value_type_from
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class value_type_from<T, typename enable_if_type<typename T::value_type>::type>
|
||||
{
|
||||
typedef typename T::value_type type;
|
||||
};
|
||||
``
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Overlapping enabler conditions]
|
||||
|
||||
Reference in New Issue
Block a user