forked from boostorg/utility
changes after pre-review
[SVN r1503]
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
CXX = g++ -I${HOME}/boost -I../../..
|
||||
|
||||
all: enable_if_constructors.run enable_if_dummy_arg_disambiguation.run enable_if_namespace_disambiguation.run enable_if_no_disambiguation.run enable_if_lazy.run enable_if_member_templates.run enable_if_partial_specializations.run
|
||||
all: enable_if_constructors.run enable_if_dummy_arg_disambiguation.run enable_if_namespace_disambiguation.run enable_if_no_disambiguation.run enable_if_lazy.run enable_if_member_templates.run enable_if_partial_specializations.run enable_if_lazy_test.run
|
||||
|
||||
enable_if_constructors.run: enable_if_constructors.exe
|
||||
./enable_if_constructors.exe
|
||||
@@ -51,5 +51,14 @@ enable_if_partial_specializations.run: enable_if_partial_specializations.exe
|
||||
enable_if_partial_specializations.exe: enable_if_partial_specializations.cpp
|
||||
$(CXX) -o enable_if_partial_specializations.exe enable_if_partial_specializations.cpp
|
||||
|
||||
|
||||
enable_if_lazy_test.run: enable_if_lazy_test.exe
|
||||
./enable_if_lazy_test.exe
|
||||
touch enable_if_lazy_test.run
|
||||
|
||||
enable_if_lazy_test.exe: enable_if_lazy_test.cpp
|
||||
$(CXX) -o enable_if_lazy_test.exe enable_if_lazy_test.cpp
|
||||
|
||||
|
||||
clean:
|
||||
-rm -f enable_if_constructors.run enable_if_dummy_arg_disambiguation.run enable_if_lazy.run enable_if_member_templates.run enable_if_namespace_disambiguation.run enable_if_no_disambiguation.run enable_if_partial_specializations.run enable_if_constructors.exe enable_if_dummy_arg_disambiguation.exe enable_if_lazy.exe enable_if_member_templates.exe enable_if_namespace_disambiguation.exe enable_if_no_disambiguation.exe enable_if_partial_specializations.exe
|
||||
-rm -f enable_if_constructors.run enable_if_dummy_arg_disambiguation.run enable_if_lazy.run enable_if_member_templates.run enable_if_namespace_disambiguation.run enable_if_no_disambiguation.run enable_if_partial_specializations.run enable_if_lazy_test.run enable_if_constructors.exe enable_if_dummy_arg_disambiguation.exe enable_if_lazy.exe enable_if_member_templates.exe enable_if_namespace_disambiguation.exe enable_if_no_disambiguation.exe enable_if_partial_specializations.exe enable_if_lazy_test.exe
|
||||
|
@@ -22,11 +22,11 @@ struct container {
|
||||
bool my_value;
|
||||
|
||||
template <class T>
|
||||
container(const T&, const typename enable_if<is_arithmetic<T>::value, T>::type * = 0):
|
||||
container(const T&, const typename enable_if<is_arithmetic<T>, T>::type * = 0):
|
||||
my_value(true) {}
|
||||
|
||||
template <class T>
|
||||
container(const T&, const typename disable_if<is_arithmetic<T>::value, T>::type * = 0):
|
||||
container(const T&, const typename disable_if<is_arithmetic<T>, T>::type * = 0):
|
||||
my_value(false) {}
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ struct xstring
|
||||
{
|
||||
template <class It>
|
||||
xstring(It begin, It end, typename
|
||||
enable_if<!is_arithmetic<It>::value>::type* = 0)
|
||||
disable_if<is_arithmetic<It> >::type* = 0)
|
||||
: data(end-begin) {}
|
||||
|
||||
int data;
|
||||
|
@@ -22,11 +22,11 @@ template <int N> struct dummy {
|
||||
};
|
||||
|
||||
template<class T>
|
||||
typename enable_if<is_arithmetic<T>::value, bool>::type
|
||||
typename enable_if<is_arithmetic<T>, bool>::type
|
||||
arithmetic_object(T t, dummy<0> = 0) { return true; }
|
||||
|
||||
template<class T>
|
||||
typename enable_if<!is_arithmetic<T>::value, bool>::type
|
||||
typename enable_if<!is_arithmetic<T>, bool>::type
|
||||
arithmetic_object(T t, dummy<1> = 0) { return false; }
|
||||
|
||||
|
||||
|
@@ -14,8 +14,8 @@
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
|
||||
using boost::enable_if;
|
||||
using boost::enable_if_lazy;
|
||||
using boost::enable_if_c;
|
||||
using boost::lazy_enable_if_c;
|
||||
using boost::is_arithmetic;
|
||||
|
||||
// This class provides a reduced example of a traits class for computing
|
||||
@@ -43,26 +43,27 @@ struct mult_traits<double, double> {
|
||||
|
||||
// Next, a forwarding function mult() is defined. It is enabled only when
|
||||
// mult_traits<T, U>::exists is true. The first version, using normal
|
||||
// enable_if, works with only some compilers (it does not work in g++):
|
||||
// enable_if_c, works with only some compilers (it does not work in g++):
|
||||
|
||||
#if 0
|
||||
template <class T, class U>
|
||||
typename enable_if<
|
||||
typename enable_if_c<
|
||||
mult_traits<T, U>::exists,
|
||||
typename mult_traits<T, U>::type>::type
|
||||
mult(const T& x, const U& y) {return x * y;}
|
||||
#endif
|
||||
|
||||
// An improved version that works with more compilers uses enable_if_lazy.
|
||||
// An improved version that works with more compilers uses lazy_enable_if_c.
|
||||
// This template removes compiler errors from invalid code used as an
|
||||
// argument to enable_if.
|
||||
// argument to enable_if_c.
|
||||
|
||||
template <class T, class U>
|
||||
typename enable_if_lazy<
|
||||
typename lazy_enable_if_c<
|
||||
mult_traits<T, U>::exists,
|
||||
mult_traits<T, U> >::type
|
||||
mult(const T& x, const U& y) {return x * y;}
|
||||
|
||||
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
|
||||
|
93
test/enable_if_lazy_test.cpp
Normal file
93
test/enable_if_lazy_test.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Copyright 2003 <20> The Trustees of Indiana University. All rights
|
||||
// reserved.
|
||||
//
|
||||
// See the file enable_if_LICENSE for licensing conditions.
|
||||
//
|
||||
// Authors: Jaakko J<>rvi (jajarvi@osl.iu.edu)
|
||||
// Jeremiah Willcock (jewillco@osl.iu.edu)
|
||||
// Andrew Lumsdaine (lums@osl.iu.edu)
|
||||
//
|
||||
|
||||
#include <boost/test/minimal.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
|
||||
using boost::lazy_enable_if;
|
||||
using boost::lazy_disable_if;
|
||||
|
||||
using boost::lazy_enable_if_c;
|
||||
using boost::lazy_disable_if_c;
|
||||
|
||||
using boost::is_arithmetic;
|
||||
|
||||
template <class T>
|
||||
struct some_traits {
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct some_traits<int> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
typedef bool type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct some_traits<double> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
typedef bool type;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct make_bool {
|
||||
typedef bool type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct make_bool<int> {};
|
||||
|
||||
template <>
|
||||
struct make_bool<double> {};
|
||||
|
||||
namespace A {
|
||||
|
||||
template<class T>
|
||||
typename lazy_enable_if<some_traits<T>, some_traits<T> >::type
|
||||
foo(T t) { return true; }
|
||||
|
||||
template<class T>
|
||||
typename lazy_enable_if_c<some_traits<T>::value, some_traits<T> >::type
|
||||
foo2(T t) { return true; }
|
||||
}
|
||||
|
||||
namespace B {
|
||||
template<class T>
|
||||
typename lazy_disable_if<some_traits<T>, make_bool<T> >::type
|
||||
foo(T t) { return false; }
|
||||
|
||||
template<class T>
|
||||
typename lazy_disable_if_c<some_traits<T>::value, make_bool<T> >::type
|
||||
foo2(T t) { return false; }
|
||||
}
|
||||
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
using namespace A;
|
||||
using namespace B;
|
||||
BOOST_TEST(foo(1));
|
||||
BOOST_TEST(foo(1.0));
|
||||
|
||||
BOOST_TEST(!foo("1"));
|
||||
BOOST_TEST(!foo(static_cast<void*>(0)));
|
||||
|
||||
BOOST_TEST(foo2(1));
|
||||
BOOST_TEST(foo2(1.0));
|
||||
|
||||
BOOST_TEST(!foo2("1"));
|
||||
BOOST_TEST(!foo2(static_cast<void*>(0)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -20,11 +20,11 @@ using boost::is_arithmetic;
|
||||
|
||||
struct container {
|
||||
template <class T>
|
||||
typename enable_if<is_arithmetic<T>::value, bool>::type
|
||||
typename enable_if<is_arithmetic<T>, bool>::type
|
||||
arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;}
|
||||
|
||||
template <class T>
|
||||
typename disable_if<is_arithmetic<T>::value, bool>::type
|
||||
typename disable_if<is_arithmetic<T>, bool>::type
|
||||
arithmetic_object(const T&) {return false;}
|
||||
};
|
||||
|
||||
|
@@ -10,22 +10,24 @@
|
||||
//
|
||||
|
||||
#include <boost/test/minimal.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
|
||||
using boost::enable_if;
|
||||
using boost::mpl::not_;
|
||||
using boost::is_arithmetic;
|
||||
|
||||
namespace A {
|
||||
template<class T>
|
||||
typename enable_if<is_arithmetic<T>::value, bool>::type
|
||||
typename enable_if<is_arithmetic<T>, bool>::type
|
||||
arithmetic_object(T t) { return true; }
|
||||
}
|
||||
|
||||
namespace B {
|
||||
template<class T>
|
||||
typename enable_if<!is_arithmetic<T>::value, bool>::type
|
||||
typename enable_if<not_<is_arithmetic<T> >, bool>::type
|
||||
arithmetic_object(T t) { return false; }
|
||||
}
|
||||
|
||||
|
@@ -10,19 +10,21 @@
|
||||
//
|
||||
|
||||
#include <boost/test/minimal.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
|
||||
using boost::mpl::not_;
|
||||
using boost::enable_if;
|
||||
using boost::is_arithmetic;
|
||||
|
||||
template<class T>
|
||||
typename enable_if<is_arithmetic<T>::value, bool>::type
|
||||
typename enable_if<is_arithmetic<T>, bool>::type
|
||||
arithmetic_object(T t) { return true; }
|
||||
|
||||
template<class T>
|
||||
typename enable_if<!is_arithmetic<T>::value, bool>::type
|
||||
typename enable_if<not_<is_arithmetic<T> >, bool>::type
|
||||
arithmetic_object(T t) { return false; }
|
||||
|
||||
|
||||
|
@@ -14,6 +14,8 @@
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_arithmetic.hpp>
|
||||
|
||||
using boost::enable_if_c;
|
||||
using boost::disable_if_c;
|
||||
using boost::enable_if;
|
||||
using boost::disable_if;
|
||||
using boost::is_arithmetic;
|
||||
@@ -22,12 +24,25 @@ template <class T, class Enable = void>
|
||||
struct tester;
|
||||
|
||||
template <class T>
|
||||
struct tester<T, typename enable_if<is_arithmetic<T>::value>::type> {
|
||||
struct tester<T, typename enable_if_c<is_arithmetic<T>::value>::type> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct tester<T, typename disable_if<is_arithmetic<T>::value>::type> {
|
||||
struct tester<T, typename disable_if_c<is_arithmetic<T>::value>::type> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template <class T, class Enable = void>
|
||||
struct tester2;
|
||||
|
||||
template <class T>
|
||||
struct tester2<T, typename enable_if<is_arithmetic<T> >::type> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct tester2<T, typename disable_if<is_arithmetic<T> >::type> {
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
@@ -40,6 +55,12 @@ int test_main(int, char*[])
|
||||
BOOST_TEST(!tester<char*>::value);
|
||||
BOOST_TEST(!tester<void*>::value);
|
||||
|
||||
BOOST_TEST(tester2<int>::value);
|
||||
BOOST_TEST(tester2<double>::value);
|
||||
|
||||
BOOST_TEST(!tester2<char*>::value);
|
||||
BOOST_TEST(!tester2<void*>::value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user