1
0
forked from boostorg/core

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

@@ -14,6 +14,7 @@
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/detail/lightweight_test.hpp>
using boost::enable_if_type;
using boost::enable_if_c;
using boost::disable_if_c;
using boost::enable_if;
@@ -46,9 +47,28 @@ struct tester2<T, typename disable_if<is_arithmetic<T> >::type> {
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class T, class Enable = void>
class tester3
{
typedef T type;
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class T>
class tester3<T, typename enable_if_type<typename T::value_type>::type>
{
typedef typename T::value_type type;
BOOST_STATIC_CONSTANT(bool, value = true);
};
struct sample_value_type
{
typedef float***& value_type;
};
int main()
{
BOOST_TEST(tester<int>::value);
BOOST_TEST(tester<double>::value);
@@ -61,6 +81,9 @@ int main()
BOOST_TEST(!tester2<char*>::value);
BOOST_TEST(!tester2<void*>::value);
BOOST_TEST(!tester3<char*>::value);
BOOST_TEST(tester3<sample_value_type>::value);
return boost::report_errors();
}