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:
Joel Falcou
2015-07-24 20:13:32 +02:00
parent d9b28783e8
commit ad513c1641
3 changed files with 53 additions and 1 deletions

View File

@@ -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]