1 // Boost enable_if library
2
3 // Copyright 2003 (c) The Trustees of Indiana University.
4
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)
8
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)
12
13 #include <boost/utility/enable_if.hpp>
14 #include <boost/type_traits/is_arithmetic.hpp>
15 #include <boost/core/lightweight_test.hpp>
16
17 using boost::enable_if_has_type;
18 using boost::enable_if_c;
19 using boost::disable_if_c;
20 using boost::enable_if;
21 using boost::disable_if;
22 using boost::is_arithmetic;
23
24 template <class T, class Enable = void>
25 struct tester;
26
27 template <class T>
28 struct tester<T, typename enable_if_c<is_arithmetic<T>::value>::type> {
29 BOOST_STATIC_CONSTANT(bool, value = true);
30 };
31
32 template <class T>
33 struct tester<T, typename disable_if_c<is_arithmetic<T>::value>::type> {
34 BOOST_STATIC_CONSTANT(bool, value = false);
35 };
36
37 template <class T, class Enable = void>
38 struct tester2;
39
40 template <class T>
41 struct tester2<T, typename enable_if<is_arithmetic<T> >::type> {
42 BOOST_STATIC_CONSTANT(bool, value = true);
43 };
44
45 template <class T>
46 struct tester2<T, typename disable_if<is_arithmetic<T> >::type> {
47 BOOST_STATIC_CONSTANT(bool, value = false);
48 };
49
50 template <class T, class Enable = void>
51 struct tester3
52 {
53 typedef T type;
54 BOOST_STATIC_CONSTANT(bool, value = false);
55 };
56
57 template <class T>
58 struct tester3<T, typename enable_if_has_type<typename T::value_type>::type>
59 {
60 typedef typename T::value_type type;
61 BOOST_STATIC_CONSTANT(bool, value = true);
62 };
63
64 struct sample_value_type
65 {
66 typedef float***& value_type;
67 };
68
main()69 int main()
70 {
71
72 BOOST_TEST(tester<int>::value);
73 BOOST_TEST(tester<double>::value);
74
75 BOOST_TEST(!tester<char*>::value);
76 BOOST_TEST(!tester<void*>::value);
77
78 BOOST_TEST(tester2<int>::value);
79 BOOST_TEST(tester2<double>::value);
80
81 BOOST_TEST(!tester2<char*>::value);
82 BOOST_TEST(!tester2<void*>::value);
83
84 BOOST_TEST(!tester3<char*>::value);
85 BOOST_TEST(tester3<sample_value_type>::value);
86
87 return boost::report_errors();
88 }
89
90