| 1 | // Copyright (C) 2003, Fernando Luis Cacciola Carballal. |
|---|
| 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 | // fernando_cacciola@hotmail.com |
|---|
| 11 | // |
|---|
| 12 | #include<iostream> |
|---|
| 13 | #include<stdexcept> |
|---|
| 14 | #include<string> |
|---|
| 15 | |
|---|
| 16 | #define BOOST_ENABLE_ASSERT_HANDLER |
|---|
| 17 | |
|---|
| 18 | #include "boost/optional/optional.hpp" |
|---|
| 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 | #ifdef __BORLANDC__ |
|---|
| 26 | #pragma hdrstop |
|---|
| 27 | #endif |
|---|
| 28 | |
|---|
| 29 | #include "boost/test/minimal.hpp" |
|---|
| 30 | |
|---|
| 31 | #include "optional_test_common.cpp" |
|---|
| 32 | |
|---|
| 33 | #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT |
|---|
| 34 | struct A |
|---|
| 35 | { |
|---|
| 36 | A ( double a0, std::string a1 ) : m_a0(a0), m_a1(a1) {} |
|---|
| 37 | |
|---|
| 38 | friend bool operator == ( A const& x, A const& y ) |
|---|
| 39 | { return x.m_a0 == y.m_a0 && x.m_a1 == y.m_a1 ; } |
|---|
| 40 | |
|---|
| 41 | double m_a0 ; |
|---|
| 42 | std::string m_a1 ; |
|---|
| 43 | } ; |
|---|
| 44 | |
|---|
| 45 | int test_main( int, char* [] ) |
|---|
| 46 | { |
|---|
| 47 | double a00 = 3.14, a10 = 6.02e-23; |
|---|
| 48 | std::string a01("pi"), a11("mol"); |
|---|
| 49 | |
|---|
| 50 | A a0(a00,a01); |
|---|
| 51 | A a1(a10,a11); |
|---|
| 52 | |
|---|
| 53 | boost::optional<A> opt1(a0); |
|---|
| 54 | |
|---|
| 55 | boost::optional<A> opt2 ( boost::in_place(a00,a01) ) ; |
|---|
| 56 | |
|---|
| 57 | boost::optional<A> opt3 ( boost::in_place<A>(a00,a01) ) ; |
|---|
| 58 | |
|---|
| 59 | BOOST_CHECK( opt1 == opt2 ) ; |
|---|
| 60 | BOOST_CHECK( opt2 == opt2 ) ; |
|---|
| 61 | BOOST_CHECK( *opt2 == a0 ) ; |
|---|
| 62 | |
|---|
| 63 | #ifndef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION |
|---|
| 64 | |
|---|
| 65 | opt2 = boost::in_place(a10,a11); |
|---|
| 66 | BOOST_CHECK( *opt2 == a1 ) ; |
|---|
| 67 | |
|---|
| 68 | opt3 = boost::in_place<A>(a10,a11); |
|---|
| 69 | BOOST_CHECK( *opt3 == a1 ) ; |
|---|
| 70 | |
|---|
| 71 | #endif |
|---|
| 72 | |
|---|
| 73 | return 0; |
|---|
| 74 | } |
|---|
| 75 | #else |
|---|
| 76 | int test_main( int, char* [] ) |
|---|
| 77 | { |
|---|
| 78 | // If in-place factories are not supported there is nothing to test |
|---|
| 79 | return 0 ; |
|---|
| 80 | } |
|---|
| 81 | #endif |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|