From b007400de4218faf33af47dd7206b1dc79a4148a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Fri, 5 Sep 2003 18:22:13 +0000 Subject: [PATCH] changes after pre-review [SVN r1503] --- test/enable_if_Makefile | 13 ++- test/enable_if_constructors.cpp | 6 +- test/enable_if_dummy_arg_disambiguation.cpp | 4 +- test/enable_if_lazy.cpp | 15 ++-- test/enable_if_lazy_test.cpp | 93 +++++++++++++++++++++ test/enable_if_member_templates.cpp | 4 +- test/enable_if_namespace_disambiguation.cpp | 6 +- test/enable_if_no_disambiguation.cpp | 6 +- test/enable_if_partial_specializations.cpp | 25 +++++- 9 files changed, 150 insertions(+), 22 deletions(-) create mode 100644 test/enable_if_lazy_test.cpp diff --git a/test/enable_if_Makefile b/test/enable_if_Makefile index ce79e96..afa125f 100644 --- a/test/enable_if_Makefile +++ b/test/enable_if_Makefile @@ -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 diff --git a/test/enable_if_constructors.cpp b/test/enable_if_constructors.cpp index a87fd8d..39b21d6 100644 --- a/test/enable_if_constructors.cpp +++ b/test/enable_if_constructors.cpp @@ -22,11 +22,11 @@ struct container { bool my_value; template - container(const T&, const typename enable_if::value, T>::type * = 0): + container(const T&, const typename enable_if, T>::type * = 0): my_value(true) {} template - container(const T&, const typename disable_if::value, T>::type * = 0): + container(const T&, const typename disable_if, T>::type * = 0): my_value(false) {} }; @@ -36,7 +36,7 @@ struct xstring { template xstring(It begin, It end, typename - enable_if::value>::type* = 0) + disable_if >::type* = 0) : data(end-begin) {} int data; diff --git a/test/enable_if_dummy_arg_disambiguation.cpp b/test/enable_if_dummy_arg_disambiguation.cpp index 9cf98b4..8735b42 100644 --- a/test/enable_if_dummy_arg_disambiguation.cpp +++ b/test/enable_if_dummy_arg_disambiguation.cpp @@ -22,11 +22,11 @@ template struct dummy { }; template -typename enable_if::value, bool>::type +typename enable_if, bool>::type arithmetic_object(T t, dummy<0> = 0) { return true; } template -typename enable_if::value, bool>::type +typename enable_if, bool>::type arithmetic_object(T t, dummy<1> = 0) { return false; } diff --git a/test/enable_if_lazy.cpp b/test/enable_if_lazy.cpp index bdafffd..f69502a 100644 --- a/test/enable_if_lazy.cpp +++ b/test/enable_if_lazy.cpp @@ -14,8 +14,8 @@ #include #include -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 { // Next, a forwarding function mult() is defined. It is enabled only when // mult_traits::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 -typename enable_if< +typename enable_if_c< mult_traits::exists, typename mult_traits::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 -typename enable_if_lazy< +typename lazy_enable_if_c< mult_traits::exists, mult_traits >::type mult(const T& x, const U& y) {return x * y;} + int test_main(int, char*[]) { diff --git a/test/enable_if_lazy_test.cpp b/test/enable_if_lazy_test.cpp new file mode 100644 index 0000000..4587623 --- /dev/null +++ b/test/enable_if_lazy_test.cpp @@ -0,0 +1,93 @@ +// +// Copyright 2003 © 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 +#include + +#include +#include + +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 +struct some_traits { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template <> +struct some_traits { + BOOST_STATIC_CONSTANT(bool, value = true); + typedef bool type; +}; + +template <> +struct some_traits { + BOOST_STATIC_CONSTANT(bool, value = true); + typedef bool type; +}; + +template +struct make_bool { + typedef bool type; +}; + +template <> +struct make_bool {}; + +template <> +struct make_bool {}; + +namespace A { + + template + typename lazy_enable_if, some_traits >::type + foo(T t) { return true; } + + template + typename lazy_enable_if_c::value, some_traits >::type + foo2(T t) { return true; } +} + +namespace B { + template + typename lazy_disable_if, make_bool >::type + foo(T t) { return false; } + + template + typename lazy_disable_if_c::value, make_bool >::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(0))); + + BOOST_TEST(foo2(1)); + BOOST_TEST(foo2(1.0)); + + BOOST_TEST(!foo2("1")); + BOOST_TEST(!foo2(static_cast(0))); + + return 0; +} + diff --git a/test/enable_if_member_templates.cpp b/test/enable_if_member_templates.cpp index 0f1de59..0870759 100644 --- a/test/enable_if_member_templates.cpp +++ b/test/enable_if_member_templates.cpp @@ -20,11 +20,11 @@ using boost::is_arithmetic; struct container { template - typename enable_if::value, bool>::type + typename enable_if, bool>::type arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;} template - typename disable_if::value, bool>::type + typename disable_if, bool>::type arithmetic_object(const T&) {return false;} }; diff --git a/test/enable_if_namespace_disambiguation.cpp b/test/enable_if_namespace_disambiguation.cpp index 24bf19e..ab4ce7b 100644 --- a/test/enable_if_namespace_disambiguation.cpp +++ b/test/enable_if_namespace_disambiguation.cpp @@ -10,22 +10,24 @@ // #include +#include #include #include using boost::enable_if; +using boost::mpl::not_; using boost::is_arithmetic; namespace A { template - typename enable_if::value, bool>::type + typename enable_if, bool>::type arithmetic_object(T t) { return true; } } namespace B { template - typename enable_if::value, bool>::type + typename enable_if >, bool>::type arithmetic_object(T t) { return false; } } diff --git a/test/enable_if_no_disambiguation.cpp b/test/enable_if_no_disambiguation.cpp index f8df451..e212456 100644 --- a/test/enable_if_no_disambiguation.cpp +++ b/test/enable_if_no_disambiguation.cpp @@ -10,19 +10,21 @@ // #include +#include #include #include +using boost::mpl::not_; using boost::enable_if; using boost::is_arithmetic; template -typename enable_if::value, bool>::type +typename enable_if, bool>::type arithmetic_object(T t) { return true; } template -typename enable_if::value, bool>::type +typename enable_if >, bool>::type arithmetic_object(T t) { return false; } diff --git a/test/enable_if_partial_specializations.cpp b/test/enable_if_partial_specializations.cpp index bce5455..dbb0421 100644 --- a/test/enable_if_partial_specializations.cpp +++ b/test/enable_if_partial_specializations.cpp @@ -14,6 +14,8 @@ #include #include +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 struct tester; template -struct tester::value>::type> { +struct tester::value>::type> { BOOST_STATIC_CONSTANT(bool, value = true); }; template -struct tester::value>::type> { +struct tester::value>::type> { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template +struct tester2; + +template +struct tester2 >::type> { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template +struct tester2 >::type> { BOOST_STATIC_CONSTANT(bool, value = false); }; @@ -40,6 +55,12 @@ int test_main(int, char*[]) BOOST_TEST(!tester::value); BOOST_TEST(!tester::value); + BOOST_TEST(tester2::value); + BOOST_TEST(tester2::value); + + BOOST_TEST(!tester2::value); + BOOST_TEST(!tester2::value); + return 0; }