]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/enable_if_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / type_traits / test / enable_if_test.cpp
1 /*
2 Copyright 2018 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4
5 Distributed under the Boost Software License,
6 Version 1.0. (See accompanying file LICENSE_1_0.txt
7 or copy at http://www.boost.org/LICENSE_1_0.txt)
8 */
9 #include <boost/type_traits/enable_if.hpp>
10 #include "test.hpp"
11
12 template<bool B>
13 struct Constant {
14 enum {
15 value = B
16 };
17 };
18
19 template<class T>
20 struct Check
21 : Constant<false> { };
22
23 template<>
24 struct Check<long>
25 : Constant<true> { };
26
27 class Construct {
28 public:
29 template<class T>
30 Construct(T, typename boost::enable_if_<Check<T>::value>::type* = 0)
31 : value_(true) { }
32 template<class T>
33 Construct(T, typename boost::enable_if_<!Check<T>::value>::type* = 0)
34 : value_(false) { }
35 bool value() const {
36 return value_;
37 }
38 private:
39 bool value_;
40 };
41
42 template<class T, class E = void>
43 struct Specialize;
44
45 template<class T>
46 struct Specialize<T, typename boost::enable_if_<Check<T>::value>::type>
47 : Constant<true> { };
48
49 template<class T>
50 struct Specialize<T, typename boost::enable_if_<!Check<T>::value>::type>
51 : Constant<false> { };
52
53 template<class T>
54 typename boost::enable_if_<Check<T>::value, bool>::type Returns(T)
55 {
56 return true;
57 }
58
59 template<class T>
60 typename boost::enable_if_<!Check<T>::value, bool>::type Returns(T)
61 {
62 return false;
63 }
64
65 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
66 template<class T>
67 boost::enable_if_t<Check<T>::value, bool> Alias(T)
68 {
69 return true;
70 }
71
72 template<class T>
73 boost::enable_if_t<!Check<T>::value, bool> Alias(T)
74 {
75 return false;
76 }
77 #endif
78
79 TT_TEST_BEGIN(enable_if)
80
81 BOOST_CHECK(!Construct(1).value());
82 BOOST_CHECK(Construct(1L).value());
83 BOOST_CHECK(!Specialize<int>::value);
84 BOOST_CHECK(Specialize<long>::value);
85 BOOST_CHECK(!Returns(1));
86 BOOST_CHECK(Returns(1L));
87 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
88 BOOST_CHECK(!Alias(1));
89 BOOST_CHECK(Alias(1L));
90 #endif
91
92 TT_TEST_END