1 // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
2 // Copyright (C) 2015 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<string>
14 #include "boost/optional/optional.hpp"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
21 #include "boost/utility/in_place_factory.hpp"
22 #include "boost/utility/typed_in_place_factory.hpp"
23 #endif
24
25 #include "boost/core/lightweight_test.hpp"
26 #include "boost/none.hpp"
27
28 struct Guard
29 {
30 double num;
31 std::string str;
GuardGuard32 Guard() : num() {}
GuardGuard33 Guard(double num_, std::string str_) : num(num_), str(str_) {}
34
operator ==(const Guard & lhs,const Guard & rhs)35 friend bool operator==(const Guard& lhs, const Guard& rhs) { return lhs.num == rhs.num && lhs.str == rhs.str; }
operator !=(const Guard & lhs,const Guard & rhs)36 friend bool operator!=(const Guard& lhs, const Guard& rhs) { return !(lhs == rhs); }
37
38 private:
39 Guard(const Guard&);
40 Guard& operator=(const Guard&);
41 };
42
43
main()44 int main()
45 {
46 #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
47 int excessive_param = 2;
48 boost::optional<Guard> og1 ( boost::in_place(1.0, "one", excessive_param) );
49 #else
50 NOTHING_TO_TEST_SO_JUST_FAIL
51 #endif
52 return 0;
53 }