| 
									
										
										
										
											2003-11-03 02:59:08 +00:00
										 |  |  | // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
 | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2003-11-03 02:59:08 +00:00
										 |  |  | // Use, modification, and distribution is subject to the Boost Software
 | 
					
						
							|  |  |  | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 | 
					
						
							|  |  |  | // http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2003-11-03 02:59:08 +00:00
										 |  |  | // See http://www.boost.org/lib/optional for documentation.
 | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | //
 | 
					
						
							|  |  |  | // You are welcome to contact the author at:
 | 
					
						
							|  |  |  | //  fernando_cacciola@hotmail.com
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | #include<iostream>
 | 
					
						
							|  |  |  | #include<stdexcept>
 | 
					
						
							|  |  |  | #include<string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define BOOST_ENABLE_ASSERT_HANDLER
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-21 14:54:32 +00:00
										 |  |  | #include "boost/optional/optional.hpp"
 | 
					
						
							| 
									
										
										
										
											2003-10-30 14:45:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2004-09-21 14:54:32 +00:00
										 |  |  | #include "boost/utility/in_place_factory.hpp"
 | 
					
						
							|  |  |  | #include "boost/utility/typed_in_place_factory.hpp"
 | 
					
						
							| 
									
										
										
										
											2003-10-30 14:45:13 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __BORLANDC__
 | 
					
						
							|  |  |  | #pragma hdrstop
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "boost/test/minimal.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "optional_test_common.cpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-30 14:45:13 +00:00
										 |  |  | #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | struct A | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   A ( double a0, std::string a1 ) : m_a0(a0), m_a1(a1) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   friend bool operator == ( A const& x, A const& y ) | 
					
						
							|  |  |  |     { return x.m_a0 == y.m_a0 && x.m_a1 == y.m_a1 ; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   double      m_a0 ; | 
					
						
							|  |  |  |   std::string m_a1 ; | 
					
						
							|  |  |  | } ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int test_main( int, char* [] ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   double a00 = 3.14, a10 = 6.02e-23; | 
					
						
							|  |  |  |   std::string a01("pi"), a11("mol"); | 
					
						
							| 
									
										
										
										
											2003-09-15 20:28:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   A a0(a00,a01); | 
					
						
							|  |  |  |   A a1(a10,a11); | 
					
						
							| 
									
										
										
										
											2003-10-30 14:45:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   boost::optional<A> opt1(a0); | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   boost::optional<A> opt2 ( boost::in_place(a00,a01) ) ; | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   boost::optional<A> opt3 ( boost::in_place<A>(a00,a01) ) ; | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   BOOST_CHECK( opt1 == opt2 ) ; | 
					
						
							| 
									
										
										
										
											2003-09-15 20:28:10 +00:00
										 |  |  |   BOOST_CHECK( opt2 == opt2 ) ; | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   BOOST_CHECK( *opt2 == a0 ) ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-27 12:28:21 +00:00
										 |  |  | #ifndef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   opt2 = boost::in_place(a10,a11); | 
					
						
							|  |  |  |   BOOST_CHECK( *opt2 == a1 ) ; | 
					
						
							| 
									
										
										
										
											2003-10-30 14:45:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-10-28 00:11:49 +00:00
										 |  |  |   opt3 = boost::in_place<A>(a10,a11); | 
					
						
							|  |  |  |   BOOST_CHECK( *opt3 == a1 ) ; | 
					
						
							| 
									
										
										
										
											2003-10-30 14:45:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-27 12:28:21 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  |   return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-10-30 14:45:13 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | int test_main( int, char* [] ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   // If in-place factories are not supported there is nothing to test
 | 
					
						
							|  |  |  |   return 0 ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2003-09-10 15:47:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-15 20:28:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 |