1 // Boost enable_if library
3 // Copyright 2003 (c) The Trustees of Indiana University.
5 // Use, modification, and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
10 // Jeremiah Willcock (jewillco at osl.iu.edu)
11 // Andrew Lumsdaine (lums at osl.iu.edu)
13 // Testing all variations of lazy_enable_if.
15 #include <boost/utility/enable_if.hpp>
16 #include <boost/type_traits/is_same.hpp>
17 #include <boost/detail/lightweight_test.hpp>
19 using boost::lazy_enable_if;
20 using boost::lazy_disable_if;
22 using boost::lazy_enable_if_c;
23 using boost::lazy_disable_if_c;
27 struct is_int_or_double {
28 BOOST_STATIC_CONSTANT(bool,
29 value = (boost::is_same<T, int>::value ||
30 boost::is_same<T, double>::value));
35 typedef typename T::does_not_exist type;
39 struct some_traits<int> {
44 struct some_traits<double> {
54 struct make_bool<int> {};
57 struct make_bool<double> {};
62 typename lazy_enable_if<is_int_or_double<T>, some_traits<T> >::type
63 foo(T t) { return true; }
66 typename lazy_enable_if_c<is_int_or_double<T>::value, some_traits<T> >::type
67 foo2(T t) { return true; }
72 typename lazy_disable_if<is_int_or_double<T>, make_bool<T> >::type
73 foo(T t) { return false; }
76 typename lazy_disable_if_c<is_int_or_double<T>::value, make_bool<T> >::type
77 foo2(T t) { return false; }
87 BOOST_TEST(!foo("1"));
88 BOOST_TEST(!foo(static_cast<void*>(0)));
91 BOOST_TEST(foo2(1.0));
93 BOOST_TEST(!foo2("1"));
94 BOOST_TEST(!foo2(static_cast<void*>(0)));
96 return boost::report_errors();