]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/optional/test/optional_test_constructible_from_other.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / optional / test / optional_test_constructible_from_other.cpp
1 // Copyright (c) 2018 Andrey Semashev
2 //
3 // Use, modification, and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 // The test verifies that Boost.Optional copy constructors do not attempt to invoke
8 // the element type initializing constructors from templated arguments
9
10 #include <boost/optional/optional.hpp>
11 #include <boost/core/enable_if.hpp>
12
13 struct no_type
14 {
15 char data;
16 };
17
18 struct yes_type
19 {
20 char data[2];
21 };
22
23 template< unsigned int Size >
24 struct size_tag {};
25
26 template< typename T, typename U >
27 struct is_constructible
28 {
29 template< typename T1, typename U1 >
30 static yes_type check_helper(size_tag< sizeof(static_cast< T1 >(U1())) >*);
31 template< typename T1, typename U1 >
32 static no_type check_helper(...);
33
34 static const bool value = sizeof(check_helper< T, U >(0)) == sizeof(yes_type);
35 };
36
37 template< typename T >
38 class wrapper
39 {
40 public:
41 wrapper() {}
42 wrapper(wrapper const&) {}
43 template< typename U >
44 wrapper(U const&, typename boost::enable_if_c< is_constructible< T, U >::value, int >::type = 0) {}
45 };
46
47 inline boost::optional< wrapper< int > > foo()
48 {
49 return boost::optional< wrapper< int > >();
50 }
51
52 int main()
53 {
54 // Invokes boost::optional copy constructor. Should not invoke wrapper constructor from U.
55 boost::optional< wrapper< int > > res = foo();
56 return 0;
57 }