mirror of
https://github.com/boostorg/utility.git
synced 2026-01-27 07:22:14 +00:00
https://svn.boost.org/svn/boost/trunk ........ r41400 | igaztanaga | 2007-11-26 08:34:13 -0800 (Mon, 26 Nov 2007) | 1 line Added missing #include <typeinfo> ........ r41401 | anthonyw | 2007-11-26 09:01:08 -0800 (Mon, 26 Nov 2007) | 1 line once_flag uses zero-initialization on POSIX as well as windows ........ r41402 | niels_dekker | 2007-11-26 09:36:52 -0800 (Mon, 26 Nov 2007) | 1 line Marked value_init_test failures on Borland C++ as "expected failures", as discussed with Fernando Cacciola. ........ r41404 | rwgk | 2007-11-26 12:46:28 -0800 (Mon, 26 Nov 2007) | 1 line g++ 4.3.0 compatibility (4.3.0 20071125 (experimental)) ........ r41405 | anthonyw | 2007-11-26 13:15:04 -0800 (Mon, 26 Nov 2007) | 1 line reverted accidental checkin of new timed_wait functions on condition_variable ........ r41406 | nasonov | 2007-11-26 13:29:04 -0800 (Mon, 26 Nov 2007) | 3 lines Remove redundant BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION. ........ r41407 | chris_kohlhoff | 2007-11-26 13:29:38 -0800 (Mon, 26 Nov 2007) | 3 lines WinCE doesn't work with all multicast addresses, and even though it doesn't support the multicast::enable_loopback option you can still get the value. ........ r41408 | dave | 2007-11-26 14:01:50 -0800 (Mon, 26 Nov 2007) | 2 lines Try to extend the workaround to SunPro 5.9, since we're marked as not working on 5.8 ........ r41409 | dave | 2007-11-26 17:40:01 -0800 (Mon, 26 Nov 2007) | 3 lines Allow Sun-5.7 and Sun-5.8 to fail loudly for Boost.Python so I can see what's really wrong. ........ r41413 | anthonyw | 2007-11-27 06:24:29 -0800 (Tue, 27 Nov 2007) | 1 line add support for relative timeouts to condition timed_wait ........ r41414 | grafik | 2007-11-27 09:53:56 -0800 (Tue, 27 Nov 2007) | 1 line Remove non-existent option info. ........ r41415 | grafik | 2007-11-27 09:55:13 -0800 (Tue, 27 Nov 2007) | 1 line Add some utility output formatting functions. ........ r41416 | grafik | 2007-11-27 09:57:15 -0800 (Tue, 27 Nov 2007) | 1 line Check empty string invariants, instead of assuming all strings are allocated. And reset strings when they are freed. ........ r41417 | grafik | 2007-11-27 09:58:50 -0800 (Tue, 27 Nov 2007) | 1 line Fix buffer overrun bug in expanding @() subexpressions. ........ r41418 | hkaiser | 2007-11-27 10:18:10 -0800 (Tue, 27 Nov 2007) | 1 line Wave: Fixed gcc warning, bumped version number. ........ r41419 | djenkins | 2007-11-27 10:57:48 -0800 (Tue, 27 Nov 2007) | 1 line Changes for msvc-9.0 /clr flag ........ r41420 | djenkins | 2007-11-27 10:59:06 -0800 (Tue, 27 Nov 2007) | 1 line Changes for msvc-9.0 /clr flag ........ r41423 | niels_dekker | 2007-11-27 13:34:08 -0800 (Tue, 27 Nov 2007) | 1 line Added value_init test for struct as used in MSVC bug report regarding value-initialization. ........ r41429 | noel_belcourt | 2007-11-27 18:27:13 -0800 (Tue, 27 Nov 2007) | 3 lines Fix pathscale rpath issue per Alain Minussi's suggestion. ........ r41430 | grafik | 2007-11-27 23:08:13 -0800 (Tue, 27 Nov 2007) | 1 line Add test for result status values of simple actions, i.e. empty actions. ........ r41431 | grafik | 2007-11-27 23:21:49 -0800 (Tue, 27 Nov 2007) | 19 lines build-system.jam * Reflect added start/end timestamps for actions in xml output. And update action rules for new args. execcmd.h * Add start/end timestamps to action timing info. execnt.c * Fix filetime_seconds calculation when time is larger than low 32 bit value. * Add calc of C time_t from Windows FILETIME. * Add start/end timestamps recording to action timing info. execunix.c * Add start/end timestamps recording to action timing info. jam.c * Change JAMDATE to use common ISO date format. make1.c * Redo __TIMING_RULE__ and __ACTION__RULE__ invocations to new argument ordering and added end/result timestamp values. ........ r41432 | chris_kohlhoff | 2007-11-28 05:26:33 -0800 (Wed, 28 Nov 2007) | 3 lines Make async operations fail with an error if the socket descriptor doesn't fit into the select call's fd_set. ........ r41433 | bgubenko | 2007-11-28 07:33:16 -0800 (Wed, 28 Nov 2007) | 1 line add "gcc*hpux*" toolset for serialization library bug on big endian platforms ........ r41436 | niels_dekker | 2007-11-28 09:19:37 -0800 (Wed, 28 Nov 2007) | 1 line Added tests for two more struct types to value_init_test -- discussed with Fernando Cacciola ........ r41439 | bgubenko | 2007-11-28 11:04:53 -0800 (Wed, 28 Nov 2007) | 1 line add "<linkflags>-lrt" for acc* toolsets ........ r41440 | grafik | 2007-11-28 12:24:17 -0800 (Wed, 28 Nov 2007) | 1 line Fix for latest Doxygen namespace file names. And support for method groups. From Samuel Debionne. ........ [SVN r41444]
202 lines
5.5 KiB
C++
202 lines
5.5 KiB
C++
// Copyright 2002, Fernando Luis Cacciola Carballal.
|
|
//
|
|
// Distributed under 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)
|
|
//
|
|
// Test program for "boost/utility/value_init.hpp"
|
|
//
|
|
// Initial: 21 Agu 2002
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
#include "boost/utility/value_init.hpp"
|
|
|
|
#ifdef __BORLANDC__
|
|
#pragma hdrstop
|
|
#endif
|
|
|
|
#include "boost/test/minimal.hpp"
|
|
|
|
//
|
|
// Sample POD type
|
|
//
|
|
struct POD
|
|
{
|
|
POD () : c(0), i(0), f(0) {}
|
|
|
|
POD ( char c_, int i_, float f_ ) : c(c_), i(i_), f(f_) {}
|
|
|
|
friend std::ostream& operator << ( std::ostream& os, POD const& pod )
|
|
{ return os << '(' << pod.c << ',' << pod.i << ',' << pod.f << ')' ; }
|
|
|
|
friend bool operator == ( POD const& lhs, POD const& rhs )
|
|
{ return lhs.f == rhs.f && lhs.c == rhs.c && lhs.i == rhs.i ; }
|
|
|
|
float f;
|
|
char c;
|
|
int i;
|
|
} ;
|
|
|
|
//
|
|
// Sample non POD type
|
|
//
|
|
struct NonPODBase
|
|
{
|
|
virtual ~NonPODBase() {}
|
|
} ;
|
|
struct NonPOD : NonPODBase
|
|
{
|
|
NonPOD () : id() {}
|
|
NonPOD ( std::string const& id_) : id(id_) {}
|
|
|
|
friend std::ostream& operator << ( std::ostream& os, NonPOD const& npod )
|
|
{ return os << '(' << npod.id << ')' ; }
|
|
|
|
friend bool operator == ( NonPOD const& lhs, NonPOD const& rhs )
|
|
{ return lhs.id == rhs.id ; }
|
|
|
|
std::string id ;
|
|
} ;
|
|
|
|
//
|
|
// Sample aggregate POD struct type
|
|
//
|
|
struct AggregatePODStruct
|
|
{
|
|
float f;
|
|
char c;
|
|
int i;
|
|
};
|
|
|
|
bool operator == ( AggregatePODStruct const& lhs, AggregatePODStruct const& rhs )
|
|
{ return lhs.f == rhs.f && lhs.c == rhs.c && lhs.i == rhs.i ; }
|
|
|
|
//
|
|
// An aggregate struct that contains an std::string and an int.
|
|
// Pavel Kuznetsov (MetaCommunications Engineering) used a struct like
|
|
// this to reproduce the Microsoft Visual C++ compiler bug, reported as
|
|
// Feedback ID 100744, "Value-initialization in new-expression"
|
|
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
|
|
//
|
|
struct StringAndInt
|
|
{
|
|
std::string s;
|
|
int i;
|
|
};
|
|
|
|
bool operator == ( StringAndInt const& lhs, StringAndInt const& rhs )
|
|
{ return lhs.s == rhs.s && lhs.i == rhs.i ; }
|
|
|
|
|
|
//
|
|
// A struct that has an explicit (user defined) destructor.
|
|
// Some compilers do not correctly value-initialize such a struct, for example:
|
|
// Microsoft Visual C++, Feedback ID 100744, "Value-initialization in new-expression"
|
|
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
|
|
//
|
|
struct StructWithDestructor
|
|
{
|
|
int i;
|
|
~StructWithDestructor() {}
|
|
};
|
|
|
|
bool operator == ( StructWithDestructor const& lhs, StructWithDestructor const& rhs )
|
|
{ return lhs.i == rhs.i ; }
|
|
|
|
|
|
//
|
|
// A struct that has a virtual function.
|
|
// Some compilers do not correctly value-initialize such a struct either, for example:
|
|
// Microsoft Visual C++, Feedback ID 100744, "Value-initialization in new-expression"
|
|
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
|
|
//
|
|
struct StructWithVirtualFunction
|
|
{
|
|
int i;
|
|
virtual void VirtualFunction();
|
|
};
|
|
|
|
void StructWithVirtualFunction::VirtualFunction()
|
|
{
|
|
}
|
|
|
|
bool operator == ( StructWithVirtualFunction const& lhs, StructWithVirtualFunction const& rhs )
|
|
{ return lhs.i == rhs.i ; }
|
|
|
|
|
|
//
|
|
// This test function tests boost::value_initialized<T> for a specific type T.
|
|
// The first argument (y) is assumed have the value of a value-initialized object.
|
|
// Returns true on success.
|
|
//
|
|
template<class T>
|
|
bool test ( T const& y, T const& z )
|
|
{
|
|
const boost::unit_test::counter_t counter_before_test = boost::minimal_test::errors_counter();
|
|
boost::value_initialized<T> x ;
|
|
BOOST_CHECK ( y == x ) ;
|
|
BOOST_CHECK ( y == boost::get(x) ) ;
|
|
static_cast<T&>(x) = z ;
|
|
boost::get(x) = z ;
|
|
BOOST_CHECK ( x == z ) ;
|
|
|
|
boost::value_initialized<T> const x_c ;
|
|
BOOST_CHECK ( y == x_c ) ;
|
|
BOOST_CHECK ( y == boost::get(x_c) ) ;
|
|
T& x_c_ref = x_c ;
|
|
x_c_ref = z ;
|
|
BOOST_CHECK ( x_c == z ) ;
|
|
|
|
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
|
boost::value_initialized<T const> cx ;
|
|
BOOST_CHECK ( y == cx ) ;
|
|
BOOST_CHECK ( y == boost::get(cx) ) ;
|
|
|
|
boost::value_initialized<T const> const cx_c ;
|
|
BOOST_CHECK ( y == cx_c ) ;
|
|
BOOST_CHECK ( y == boost::get(cx_c) ) ;
|
|
#endif
|
|
return boost::minimal_test::errors_counter() == counter_before_test ;
|
|
}
|
|
|
|
int test_main(int, char **)
|
|
{
|
|
BOOST_CHECK ( test( 0,1234 ) ) ;
|
|
BOOST_CHECK ( test( 0.0,12.34 ) ) ;
|
|
BOOST_CHECK ( test( POD(0,0,0.0), POD('a',1234,56.78) ) ) ;
|
|
BOOST_CHECK ( test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ) ;
|
|
|
|
NonPOD NonPOD_object( std::string("NonPOD_object") );
|
|
BOOST_CHECK ( test<NonPOD *>( 0, &NonPOD_object ) ) ;
|
|
|
|
AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 };
|
|
AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 };
|
|
BOOST_CHECK ( test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct) );
|
|
|
|
StringAndInt stringAndInt0;
|
|
StringAndInt stringAndInt1;
|
|
stringAndInt0.i = 0;
|
|
stringAndInt1.i = 1;
|
|
stringAndInt1.s = std::string("1");
|
|
BOOST_CHECK ( test(stringAndInt0, stringAndInt1) );
|
|
|
|
StructWithDestructor structWithDestructor0;
|
|
StructWithDestructor structWithDestructor1;
|
|
structWithDestructor0.i = 0;
|
|
structWithDestructor1.i = 1;
|
|
BOOST_CHECK ( test(structWithDestructor0, structWithDestructor1) );
|
|
|
|
StructWithVirtualFunction structWithVirtualFunction0;
|
|
StructWithVirtualFunction structWithVirtualFunction1;
|
|
structWithVirtualFunction0.i = 0;
|
|
structWithVirtualFunction1.i = 1;
|
|
BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) );
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
unsigned int expected_failures = 0;
|