]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/any/test/any_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / any / test / any_test.cpp
1 // Copyright Kevlin Henney, 2000, 2001. All rights reserved.
2 // Copyright Antony Polukhin, 2013-2022.
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // what: unit tests for variant type boost::any
9 // who: contributed by Kevlin Henney
10 // when: July 2001, 2013, 2014
11 // where: tested with BCC 5.5, MSVC 6.0, and g++ 2.95
12
13 #include <boost/any.hpp>
14
15 #include "basic_test.hpp"
16
17 static const std::string& returning_string1()
18 {
19 static const std::string ret("foo");
20 return ret;
21 }
22
23 static std::string returning_string2()
24 {
25 static const std::string ret("foo");
26 return ret;
27 }
28
29 static void test_with_func()
30 {
31 std::string s;
32 s = boost::any_cast<std::string>(returning_string1());
33 s = boost::any_cast<const std::string&>(returning_string1());
34
35 s = boost::any_cast<std::string>(returning_string2());
36 s = boost::any_cast<const std::string&>(returning_string2());
37
38 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
39 #if !defined(__INTEL_COMPILER) && !defined(__ICL) && (!defined(_MSC_VER) || _MSC_VER != 1600)
40 // Intel compiler thinks that it must choose the `any_cast(const any&)` function
41 // instead of the `any_cast(const any&&)`.
42 // Bug was not reported because of missing premier support account + annoying
43 // registrations requirements.
44
45 // MSVC-10 had a bug:
46 //
47 // any.hpp(291) : error C2440: 'return' : cannot convert.
48 // Conversion loses qualifiers
49 // any_test.cpp(304) : see reference to function template instantiation
50 //
51 // This issue was fixed in MSVC-11.
52
53 s = boost::any_cast<std::string&&>(returning_string1());
54 #endif
55
56 s = boost::any_cast<std::string&&>(returning_string2());
57 #endif
58 }
59
60 int main() {
61 test_with_func();
62
63 return any_tests::basic_tests<boost::any>::run_tests();
64 }
65