]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/core/test/eif_constructors.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / core / test / eif_constructors.cpp
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.hpp>
15 #include <boost/detail/lightweight_test.hpp>
16
17 using boost::enable_if;
18 using boost::disable_if;
19 using boost::is_arithmetic;
20
21 struct container {
22 bool my_value;
23
24 template <class T>
25 container(const T&, const typename enable_if<is_arithmetic<T>, T>::type * = 0):
26 my_value(true) {}
27
28 template <class T>
29 container(const T&, const typename disable_if<is_arithmetic<T>, T>::type * = 0):
30 my_value(false) {}
31 };
32
33 // example from Howard Hinnant (tests enable_if template members of a templated class)
34 template <class charT>
35 struct xstring
36 {
37 template <class It>
38 xstring(It begin, It end, typename
39 disable_if<is_arithmetic<It> >::type* = 0)
40 : data(end-begin) {}
41
42 int data;
43 };
44
45
46 int main()
47 {
48
49 BOOST_TEST(container(1).my_value);
50 BOOST_TEST(container(1.0).my_value);
51
52 BOOST_TEST(!container("1").my_value);
53 BOOST_TEST(!container(static_cast<void*>(0)).my_value);
54
55 char sa[] = "123456";
56 BOOST_TEST(xstring<char>(sa, sa+6).data == 6);
57
58
59 return boost::report_errors();
60 }
61