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
17using boost::enable_if_has_type;
18using boost::enable_if_c;
19using boost::disable_if_c;
20using boost::enable_if;
21using boost::disable_if;
22using boost::is_arithmetic;
23
24template <class T, class Enable = void>
25struct tester;
26
27template <class T>
28struct tester<T, typename enable_if_c<is_arithmetic<T>::value>::type> {
29 BOOST_STATIC_CONSTANT(bool, value = true);
30};
31
32template <class T>
33struct tester<T, typename disable_if_c<is_arithmetic<T>::value>::type> {
34 BOOST_STATIC_CONSTANT(bool, value = false);
35};
36
37template <class T, class Enable = void>
38struct tester2;
39
40template <class T>
41struct tester2<T, typename enable_if<is_arithmetic<T> >::type> {
42 BOOST_STATIC_CONSTANT(bool, value = true);
43};
44
45template <class T>
46struct tester2<T, typename disable_if<is_arithmetic<T> >::type> {
47 BOOST_STATIC_CONSTANT(bool, value = false);
48};
49
50template <class T, class Enable = void>
51struct tester3
52{
53 typedef T type;
54 BOOST_STATIC_CONSTANT(bool, value = false);
55};
56
57template <class T>
58struct 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
64struct sample_value_type
65{
66 typedef float***& value_type;
67};
68
69int 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

source code of boost/libs/core/test/eif_partial_specializations.cpp