]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/optional/test/optional_test_minimum_requirements.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / optional / test / optional_test_minimum_requirements.cpp
CommitLineData
7c673cae
FG
1// Copyright (C) 2014-2015 Andrzej Krzemienski.
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// See http://www.boost.org/lib/optional for documentation.
8//
9// You are welcome to contact the author at:
10// akrzemi1@gmail.com
11
12#include "boost/optional/optional.hpp"
13
20effc67 14#ifdef BOOST_BORLANDC
7c673cae
FG
15#pragma hdrstop
16#endif
17
20effc67 18#include <string>
7c673cae
FG
19#include "boost/core/lightweight_test.hpp"
20#include "boost/none.hpp"
21
22class NonConstructible
23{
24private:
25 NonConstructible();
26 NonConstructible(NonConstructible const&);
27#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
28 NonConstructible(NonConstructible &&);
29#endif
30};
31
32void test_non_constructible()
33{
34 boost::optional<NonConstructible> o;
35 BOOST_TEST(!o);
36 BOOST_TEST(o == boost::none);
37 BOOST_TEST_THROWS(o.value(), boost::bad_optional_access);
38}
39
40class Guard
41{
42public:
43 explicit Guard(int) {}
44private:
45 Guard();
46 Guard(Guard const&);
47#if (!defined BOOST_NO_CXX11_RVALUE_REFERENCES)
48 Guard(Guard &&);
49#endif
50};
51
52void test_guard()
53{
54 boost::optional<Guard> o;
55 o.emplace(1);
56 BOOST_TEST(o);
57 BOOST_TEST(o != boost::none);
58}
59
60void test_non_assignable()
61{
62 boost::optional<const std::string> o;
63 o.emplace("cat");
64 BOOST_TEST(o);
65 BOOST_TEST(o != boost::none);
66 BOOST_TEST_EQ(*o, std::string("cat"));
67}
68
69int main()
70{
71 test_non_constructible();
72 test_guard();
73 test_non_assignable();
74
75 return boost::report_errors();
76}