]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/optional/test/optional_test_constructible_from_other.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / optional / test / optional_test_constructible_from_other.cpp
CommitLineData
92f5a8d4
TL
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
13struct no_type
14{
15 char data;
16};
17
18struct yes_type
19{
20 char data[2];
21};
22
23template< unsigned int Size >
24struct size_tag {};
25
26template< typename T, typename U >
27struct is_constructible
28{
f67539c2
TL
29 static U& get();
30
31 template< typename T1 >
32 static yes_type check_helper(size_tag< sizeof(static_cast< T1 >(get())) >*);
33 template< typename T1 >
92f5a8d4
TL
34 static no_type check_helper(...);
35
f67539c2 36 static const bool value = sizeof(check_helper< T >(0)) == sizeof(yes_type);
92f5a8d4
TL
37};
38
39template< typename T >
40class wrapper
41{
42public:
43 wrapper() {}
44 wrapper(wrapper const&) {}
45 template< typename U >
46 wrapper(U const&, typename boost::enable_if_c< is_constructible< T, U >::value, int >::type = 0) {}
47};
48
49inline boost::optional< wrapper< int > > foo()
50{
51 return boost::optional< wrapper< int > >();
52}
53
54int main()
55{
56 // Invokes boost::optional copy constructor. Should not invoke wrapper constructor from U.
57 boost::optional< wrapper< int > > res = foo();
58 return 0;
59}