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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user