Add enable_if_ and enable_if_t. Sever dependency on Core.

This commit is contained in:
Glen Fernandes
2018-08-25 21:00:17 -04:00
parent 7639c5820b
commit 2baafd4a3a
9 changed files with 183 additions and 8 deletions
+92
View File
@@ -0,0 +1,92 @@
/*
Copyright 2018 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt
or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/type_traits/enable_if.hpp>
#include "test.hpp"
template<bool B>
struct Constant {
enum {
value = B
};
};
template<class T>
struct Check
: Constant<false> { };
template<>
struct Check<long>
: Constant<true> { };
class Construct {
public:
template<class T>
Construct(T, typename boost::enable_if_<Check<T>::value>::type* = 0)
: value_(true) { }
template<class T>
Construct(T, typename boost::enable_if_<!Check<T>::value>::type* = 0)
: value_(false) { }
bool value() const {
return value_;
}
private:
bool value_;
};
template<class T, class E = void>
struct Specialize;
template<class T>
struct Specialize<T, typename boost::enable_if_<Check<T>::value>::type>
: Constant<true> { };
template<class T>
struct Specialize<T, typename boost::enable_if_<!Check<T>::value>::type>
: Constant<false> { };
template<class T>
typename boost::enable_if_<Check<T>::value, bool>::type Returns(T)
{
return true;
}
template<class T>
typename boost::enable_if_<!Check<T>::value, bool>::type Returns(T)
{
return false;
}
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
template<class T>
boost::enable_if_t<Check<T>::value, bool> Alias(T)
{
return true;
}
template<class T>
boost::enable_if_t<!Check<T>::value, bool> Alias(T)
{
return false;
}
#endif
TT_TEST_BEGIN(enable_if)
BOOST_CHECK(!Construct(1).value());
BOOST_CHECK(Construct(1L).value());
BOOST_CHECK(!Specialize<int>::value);
BOOST_CHECK(Specialize<long>::value);
BOOST_CHECK(!Returns(1));
BOOST_CHECK(Returns(1L));
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
BOOST_CHECK(!Alias(1));
BOOST_CHECK(Alias(1L));
#endif
TT_TEST_END
+2 -2
View File
@@ -11,7 +11,7 @@
#endif
#include "test.hpp"
#include "check_integral_constant.hpp"
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/enable_if.hpp>
template <class T>
@@ -30,7 +30,7 @@ template<typename T>
struct test_bug_4530
{
template<typename A>
test_bug_4530(A&&, typename boost::enable_if< ::tt::is_convertible<A&&, T> >::type* =0);
test_bug_4530(A&&, typename boost::enable_if_< ::tt::is_convertible<A&&, T>::value >::type* =0);
};
struct A4530