]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/optional/test/optional_test_io.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / optional / test / optional_test_io.cpp
1 // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
2 // Copyright (C) 2014 Andrzej Krzemienski.
3 //
4 // Use, modification, and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // See http://www.boost.org/lib/optional for documentation.
9 //
10 // You are welcome to contact the author at:
11 // fernando_cacciola@hotmail.com
12
13 #include <sstream>
14 #include "boost/optional/optional.hpp"
15 #include "boost/optional/optional_io.hpp"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #include "boost/core/lightweight_test.hpp"
22
23 using boost::optional;
24
25 template<class Opt>
26 void test2( Opt o, Opt buff )
27 {
28 std::stringstream s ;
29
30 const int markv = 123 ;
31 int mark = 0 ;
32
33 s << o << " " << markv ;
34 s >> buff >> mark ;
35
36 BOOST_TEST( buff == o ) ;
37 BOOST_TEST( mark == markv ) ;
38 }
39
40
41 template<class T>
42 void test( T v, T w )
43 {
44 test2( boost::make_optional(v), optional<T> ());
45 test2( boost::make_optional(v), boost::make_optional(w));
46 test2( optional<T> () , optional<T> ());
47 test2( optional<T> () , boost::make_optional(w));
48 }
49
50
51 template <class T>
52 void subtest_tag_none_reversibility_with_optional(optional<T> ov)
53 {
54 std::stringstream s;
55 s << boost::none;
56 s >> ov;
57 BOOST_TEST(!ov);
58 }
59
60 template <class T>
61 void subtest_tag_none_equivalence_with_optional()
62 {
63 std::stringstream s, r;
64 optional<T> ov;
65 s << boost::none;
66 r << ov;
67 BOOST_TEST_EQ(s.str(), r.str());
68 }
69
70 template <class T>
71 void test_tag_none(T v)
72 {
73 subtest_tag_none_reversibility_with_optional(optional<T>(v));
74 subtest_tag_none_reversibility_with_optional(optional<T>());
75 subtest_tag_none_equivalence_with_optional<T>();
76 }
77
78
79 int main()
80 {
81 test(1,2);
82 test(std::string("hello"), std::string("buffer"));
83 test_tag_none(10);
84 test_tag_none(std::string("text"));
85
86 return boost::report_errors();
87 }