bcbboost branch rebased on current release

[SVN r49389]
This commit is contained in:
Nicola Musatti
2008-10-19 14:43:01 +00:00
13 changed files with 236 additions and 607 deletions

View File

@ -8,9 +8,6 @@
// See http://www.boost.org/libs/utility/operators.htm for documentation. // See http://www.boost.org/libs/utility/operators.htm for documentation.
// Revision History // Revision History
// 07 Aug 08 Added "euclidean" spelling. (Daniel Frey)
// 03 Apr 08 Make sure "convertible to bool" is sufficient
// for T::operator<, etc. (Daniel Frey)
// 24 May 07 Changed empty_base to depend on T, see // 24 May 07 Changed empty_base to depend on T, see
// http://svn.boost.org/trac/boost/ticket/979 // http://svn.boost.org/trac/boost/ticket/979
// 21 Oct 02 Modified implementation of operators to allow compilers with a // 21 Oct 02 Modified implementation of operators to allow compilers with a
@ -127,34 +124,34 @@ namespace boost
template <class T, class U, class B = ::boost::detail::empty_base<T> > template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct less_than_comparable2 : B struct less_than_comparable2 : B
{ {
friend bool operator<=(const T& x, const U& y) { return !static_cast<bool>(x > y); } friend bool operator<=(const T& x, const U& y) { return !(x > y); }
friend bool operator>=(const T& x, const U& y) { return !static_cast<bool>(x < y); } friend bool operator>=(const T& x, const U& y) { return !(x < y); }
friend bool operator>(const U& x, const T& y) { return y < x; } friend bool operator>(const U& x, const T& y) { return y < x; }
friend bool operator<(const U& x, const T& y) { return y > x; } friend bool operator<(const U& x, const T& y) { return y > x; }
friend bool operator<=(const U& x, const T& y) { return !static_cast<bool>(y < x); } friend bool operator<=(const U& x, const T& y) { return !(y < x); }
friend bool operator>=(const U& x, const T& y) { return !static_cast<bool>(y > x); } friend bool operator>=(const U& x, const T& y) { return !(y > x); }
}; };
template <class T, class B = ::boost::detail::empty_base<T> > template <class T, class B = ::boost::detail::empty_base<T> >
struct less_than_comparable1 : B struct less_than_comparable1 : B
{ {
friend bool operator>(const T& x, const T& y) { return y < x; } friend bool operator>(const T& x, const T& y) { return y < x; }
friend bool operator<=(const T& x, const T& y) { return !static_cast<bool>(y < x); } friend bool operator<=(const T& x, const T& y) { return !(y < x); }
friend bool operator>=(const T& x, const T& y) { return !static_cast<bool>(x < y); } friend bool operator>=(const T& x, const T& y) { return !(x < y); }
}; };
template <class T, class U, class B = ::boost::detail::empty_base<T> > template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct equality_comparable2 : B struct equality_comparable2 : B
{ {
friend bool operator==(const U& y, const T& x) { return x == y; } friend bool operator==(const U& y, const T& x) { return x == y; }
friend bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); } friend bool operator!=(const U& y, const T& x) { return !(x == y); }
friend bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); } friend bool operator!=(const T& y, const U& x) { return !(y == x); }
}; };
template <class T, class B = ::boost::detail::empty_base<T> > template <class T, class B = ::boost::detail::empty_base<T> >
struct equality_comparable1 : B struct equality_comparable1 : B
{ {
friend bool operator!=(const T& x, const T& y) { return !static_cast<bool>(x == y); } friend bool operator!=(const T& x, const T& y) { return !(x == y); }
}; };
// A macro which produces "name_2left" from "name". // A macro which produces "name_2left" from "name".
@ -359,7 +356,7 @@ struct equivalent2 : B
{ {
friend bool operator==(const T& x, const U& y) friend bool operator==(const T& x, const U& y)
{ {
return !static_cast<bool>(x < y) && !static_cast<bool>(x > y); return !(x < y) && !(x > y);
} }
}; };
@ -368,7 +365,7 @@ struct equivalent1 : B
{ {
friend bool operator==(const T&x, const T&y) friend bool operator==(const T&x, const T&y)
{ {
return !static_cast<bool>(x < y) && !static_cast<bool>(y < x); return !(x < y) && !(y < x);
} }
}; };
@ -376,17 +373,17 @@ template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct partially_ordered2 : B struct partially_ordered2 : B
{ {
friend bool operator<=(const T& x, const U& y) friend bool operator<=(const T& x, const U& y)
{ return static_cast<bool>(x < y) || static_cast<bool>(x == y); } { return (x < y) || (x == y); }
friend bool operator>=(const T& x, const U& y) friend bool operator>=(const T& x, const U& y)
{ return static_cast<bool>(x > y) || static_cast<bool>(x == y); } { return (x > y) || (x == y); }
friend bool operator>(const U& x, const T& y) friend bool operator>(const U& x, const T& y)
{ return y < x; } { return y < x; }
friend bool operator<(const U& x, const T& y) friend bool operator<(const U& x, const T& y)
{ return y > x; } { return y > x; }
friend bool operator<=(const U& x, const T& y) friend bool operator<=(const U& x, const T& y)
{ return static_cast<bool>(y > x) || static_cast<bool>(y == x); } { return (y > x) || (y == x); }
friend bool operator>=(const U& x, const T& y) friend bool operator>=(const U& x, const T& y)
{ return static_cast<bool>(y < x) || static_cast<bool>(y == x); } { return (y < x) || (y == x); }
}; };
template <class T, class B = ::boost::detail::empty_base<T> > template <class T, class B = ::boost::detail::empty_base<T> >
@ -395,9 +392,9 @@ struct partially_ordered1 : B
friend bool operator>(const T& x, const T& y) friend bool operator>(const T& x, const T& y)
{ return y < x; } { return y < x; }
friend bool operator<=(const T& x, const T& y) friend bool operator<=(const T& x, const T& y)
{ return static_cast<bool>(x < y) || static_cast<bool>(x == y); } { return (x < y) || (x == y); }
friend bool operator>=(const T& x, const T& y) friend bool operator>=(const T& x, const T& y)
{ return static_cast<bool>(y < x) || static_cast<bool>(x == y); } { return (y < x) || (x == y); }
}; };
// Combined operator classes (contributed by Daryle Walker) ----------------// // Combined operator classes (contributed by Daryle Walker) ----------------//
@ -583,35 +580,7 @@ struct ordered_euclidian_ring_operators1
: totally_ordered1<T : totally_ordered1<T
, euclidian_ring_operators1<T, B , euclidian_ring_operators1<T, B
> > {}; > > {};
template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct euclidean_ring_operators2
: ring_operators2<T, U
, dividable2<T, U
, dividable2_left<T, U
, modable2<T, U
, modable2_left<T, U, B
> > > > > {};
template <class T, class B = ::boost::detail::empty_base<T> >
struct euclidean_ring_operators1
: ring_operators1<T
, dividable1<T
, modable1<T, B
> > > {};
template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct ordered_euclidean_ring_operators2
: totally_ordered2<T, U
, euclidean_ring_operators2<T, U, B
> > {};
template <class T, class B = ::boost::detail::empty_base<T> >
struct ordered_euclidean_ring_operators1
: totally_ordered1<T
, euclidean_ring_operators1<T, B
> > {};
template <class T, class P, class B = ::boost::detail::empty_base<T> > template <class T, class P, class B = ::boost::detail::empty_base<T> >
struct input_iteratable struct input_iteratable
: equality_comparable1<T : equality_comparable1<T
@ -868,8 +837,6 @@ BOOST_OPERATOR_TEMPLATE(field_operators)
BOOST_OPERATOR_TEMPLATE(ordered_field_operators) BOOST_OPERATOR_TEMPLATE(ordered_field_operators)
BOOST_OPERATOR_TEMPLATE(euclidian_ring_operators) BOOST_OPERATOR_TEMPLATE(euclidian_ring_operators)
BOOST_OPERATOR_TEMPLATE(ordered_euclidian_ring_operators) BOOST_OPERATOR_TEMPLATE(ordered_euclidian_ring_operators)
BOOST_OPERATOR_TEMPLATE(euclidean_ring_operators)
BOOST_OPERATOR_TEMPLATE(ordered_euclidean_ring_operators)
BOOST_OPERATOR_TEMPLATE2(input_iteratable) BOOST_OPERATOR_TEMPLATE2(input_iteratable)
BOOST_OPERATOR_TEMPLATE1(output_iteratable) BOOST_OPERATOR_TEMPLATE1(output_iteratable)
BOOST_OPERATOR_TEMPLATE2(forward_iteratable) BOOST_OPERATOR_TEMPLATE2(forward_iteratable)

View File

@ -173,12 +173,6 @@ class unwrap_reference
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T> inline typename unwrap_reference<T>::type&
unwrap_ref(T& t)
{
return t;
}
} // namespace boost } // namespace boost
#endif // #ifndef BOOST_REF_HPP_INCLUDED #endif // #ifndef BOOST_REF_HPP_INCLUDED

View File

@ -10,47 +10,6 @@
# error Boost result_of - do not include this file! # error Boost result_of - do not include this file!
#endif #endif
#if defined(BOOST_HAS_DECLTYPE)
// As of N2588, C++0x result_of only supports function call
// expressions of the form f(x). This precludes support for member
// function pointers, which are invoked with expressions of the form
// o->*f(x). This implementation supports both.
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
: mpl::if_<
mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
, detail::result_of_impl<
typename remove_cv<F>::type,
typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false
>
, detail::result_of_decltype_impl<
F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))
>
>::type
{};
namespace detail {
# define BOOST_RESULT_OF_STATIC_MEMBERS(z, n, _) \
static T ## n t ## n; \
/**/
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
class result_of_decltype_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
{
static F f;
BOOST_PP_REPEAT(BOOST_PP_ITERATION(), BOOST_RESULT_OF_STATIC_MEMBERS, _)
public:
typedef decltype(f(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),t))) type;
};
} // namespace detail
#else // defined(BOOST_HAS_DECLTYPE)
// CWPro8 requires an argument in a function type specialization // CWPro8 requires an argument in a function type specialization
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0
# define BOOST_RESULT_OF_ARGS void # define BOOST_RESULT_OF_ARGS void
@ -62,22 +21,11 @@ public:
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of<F(BOOST_RESULT_OF_ARGS)> struct result_of<F(BOOST_RESULT_OF_ARGS)>
: mpl::if_< : boost::detail::result_of_impl<F, F(BOOST_RESULT_OF_ARGS), (boost::detail::has_result_type<F>::value)> {};
mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
, boost::detail::result_of_impl<
typename remove_cv<F>::type,
typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS),
(boost::detail::has_result_type<F>::value)>
, boost::detail::result_of_impl<
F,
F(BOOST_RESULT_OF_ARGS),
(boost::detail::has_result_type<F>::value)> >::type { };
#endif #endif
#undef BOOST_RESULT_OF_ARGS #undef BOOST_RESULT_OF_ARGS
#endif // defined(BOOST_HAS_DECLTYPE)
#if BOOST_PP_ITERATION() >= 1 #if BOOST_PP_ITERATION() >= 1
namespace detail { namespace detail {

View File

@ -10,18 +10,13 @@
#define BOOST_RESULT_OF_HPP #define BOOST_RESULT_OF_HPP
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/preprocessor/iteration/iterate.hpp> #include <boost/type_traits/ice.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp> #include <boost/type.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/detail/workaround.hpp> #include <boost/detail/workaround.hpp>
#include <boost/mpl/has_xxx.hpp> #include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/if.hpp> #include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp> #include <boost/mpl/bool.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_member_function_pointer.hpp>
#include <boost/type_traits/remove_cv.hpp>
#ifndef BOOST_RESULT_OF_NUM_ARGS #ifndef BOOST_RESULT_OF_NUM_ARGS
# define BOOST_RESULT_OF_NUM_ARGS 10 # define BOOST_RESULT_OF_NUM_ARGS 10
@ -37,7 +32,6 @@ namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
template<typename F, typename FArgs, bool HasResultType> struct result_of_impl; template<typename F, typename FArgs, bool HasResultType> struct result_of_impl;
template<typename F> struct result_of_decltype_impl;
template<typename F> template<typename F>
struct result_of_void_impl struct result_of_void_impl
@ -57,11 +51,6 @@ struct result_of_void_impl<R (&)(void)>
typedef R type; typedef R type;
}; };
// Determine the return type of a function pointer or pointer to member.
template<typename F, typename FArgs>
struct result_of_pointer
: result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
template<typename F, typename FArgs> template<typename F, typename FArgs>
struct result_of_impl<F, FArgs, true> struct result_of_impl<F, FArgs, true>
{ {

View File

@ -7,7 +7,6 @@
// 21 Ago 2002 (Created) Fernando Cacciola // 21 Ago 2002 (Created) Fernando Cacciola
// 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker // 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker
// 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola // 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola
// 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola
// //
#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
@ -23,7 +22,6 @@
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits/cv_traits.hpp> #include <boost/type_traits/cv_traits.hpp>
#include <boost/type_traits/alignment_of.hpp> #include <boost/type_traits/alignment_of.hpp>
#include <boost/swap.hpp>
#include <cstring> #include <cstring>
#include <new> #include <new>
@ -95,11 +93,6 @@ class value_initialized
return wrapper_address()->data; return wrapper_address()->data;
} }
void swap(value_initialized & arg)
{
::boost::swap( this->data(), arg.data() );
}
operator T&() const { return this->data(); } operator T&() const { return this->data(); }
} ; } ;
@ -117,12 +110,6 @@ T& get ( value_initialized<T>& x )
return x.data() ; return x.data() ;
} }
template<class T>
void swap ( value_initialized<T> & lhs, value_initialized<T> & rhs )
{
lhs.swap(rhs) ;
}
class initialized_value_t class initialized_value_t
{ {

View File

@ -24,7 +24,6 @@
<a href="iterator_adaptors.htm">iterator_adaptors</a><br> <a href="iterator_adaptors.htm">iterator_adaptors</a><br>
<a href="generator_iterator.htm">generator iterator adaptors</a><br> <a href="generator_iterator.htm">generator iterator adaptors</a><br>
<a href="operators.htm">operators</a><br> <a href="operators.htm">operators</a><br>
<a href="swap.html">swap</a><br>
<a href="throw_exception.html">throw_exception</a><br> <a href="throw_exception.html">throw_exception</a><br>
<a href="utility.htm">utility</a><br> <a href="utility.htm">utility</a><br>
<a href="value_init.htm">value_init</a></p> <a href="value_init.htm">value_init</a></p>

View File

@ -1420,9 +1420,9 @@ T operator+( T lhs, const T&amp; rhs )
<tr> <tr>
<td><code><a name= <td><code><a name=
"euclidean_ring_operators1">euclidean_ring_operators&lt;T&gt;</a></code><br> "euclidian_ring_operators1">euclidian_ring_operators&lt;T&gt;</a></code><br>
<code>euclidean_ring_operators1&lt;T&gt;</code></td> <code>euclidian_ring_operators1&lt;T&gt;</code></td>
<td> <td>
<ul> <ul>
@ -1439,9 +1439,9 @@ T operator+( T lhs, const T&amp; rhs )
<tr> <tr>
<td><code><a name= <td><code><a name=
"euclidean_ring_operators2">euclidean_ring_operators&lt;T, "euclidian_ring_operators2">euclidian_ring_operators&lt;T,
U&gt;</a></code><br> U&gt;</a></code><br>
<code>euclidean_ring_operators2&lt;T, U&gt;</code></td> <code>euclidian_ring_operators2&lt;T, U&gt;</code></td>
<td> <td>
<ul> <ul>
@ -1464,14 +1464,14 @@ T operator+( T lhs, const T&amp; rhs )
<tr> <tr>
<td><code><a name= <td><code><a name=
"ordered_euclidean_ring_operators1">ordered_euclidean_ring_operators&lt;T&gt;</a></code><br> "ordered_euclidian_ring_operators1">ordered_euclidian_ring_operators&lt;T&gt;</a></code><br>
<code>ordered_euclidean_ring_operators1&lt;T&gt;</code></td> <code>ordered_euclidian_ring_operators1&lt;T&gt;</code></td>
<td> <td>
<ul> <ul>
<li><code><a href= <li><code><a href=
"#euclidean_ring_operators1">euclidean_ring_operators&lt;T&gt;</a></code></li> "#euclidian_ring_operators1">euclidian_ring_operators&lt;T&gt;</a></code></li>
<li><code><a href= <li><code><a href=
"#totally_ordered1">totally_ordered&lt;T&gt;</a></code></li> "#totally_ordered1">totally_ordered&lt;T&gt;</a></code></li>
@ -1481,14 +1481,14 @@ T operator+( T lhs, const T&amp; rhs )
<tr> <tr>
<td><code><a name= <td><code><a name=
"ordered_euclidean_ring_operators2">ordered_euclidean_ring_operators&lt;T, "ordered_euclidian_ring_operators2">ordered_euclidian_ring_operators&lt;T,
U&gt;</a></code><br> U&gt;</a></code><br>
<code>ordered_euclidean_ring_operators2&lt;T, U&gt;</code></td> <code>ordered_euclidian_ring_operators2&lt;T, U&gt;</code></td>
<td> <td>
<ul> <ul>
<li><code><a href= <li><code><a href=
"#euclidean_ring_operators2">euclidean_ring_operators&lt;T, "#euclidian_ring_operators2">euclidian_ring_operators&lt;T,
U&gt;</a></code></li> U&gt;</a></code></li>
<li><code><a href="#totally_ordered2">totally_ordered&lt;T, <li><code><a href="#totally_ordered2">totally_ordered&lt;T,
@ -1498,15 +1498,6 @@ T operator+( T lhs, const T&amp; rhs )
</tr> </tr>
</table> </table>
<h4>Spelling: euclidean vs. euclidian</h4>
<p>Older versions of the Boost.Operators library used
&quot;<code>euclidian</code>&quot;, but it was pointed out that
&quot;<code>euclidean</code>&quot; is the more common spelling.
To be compatible with older version, the library now supports
both spellings.
</p>
<h3><a name="ex_oprs">Example</a> Templates</h3> <h3><a name="ex_oprs">Example</a> Templates</h3>
<p>The arithmetic operator class templates <code><a href= <p>The arithmetic operator class templates <code><a href=
@ -1585,8 +1576,9 @@ T operator+( T lhs, const T&amp; rhs )
<p>The <cite><a href="operators_test.cpp">operators_test.cpp</a></cite> <p>The <cite><a href="operators_test.cpp">operators_test.cpp</a></cite>
program demonstrates the use of the arithmetic operator templates, and program demonstrates the use of the arithmetic operator templates, and
can also be used to verify correct operation. Check the compiler status can also be used to verify correct operation. Check the <a href=
report for the test results with selected platforms.</p> "../../status/compiler_status.html">compiler status report</a> for the
test results with selected platforms.</p>
<h2><a name="deref">Dereference</a> Operators and Iterator Helpers</h2> <h2><a name="deref">Dereference</a> Operators and Iterator Helpers</h2>
@ -2127,10 +2119,10 @@ public:
backward-compatible.</p> backward-compatible.</p>
<hr> <hr>
<p>Revised: 7 Aug 2008</p> <p>Revised: 29 Oct 2004</p>
<p>Copyright &copy; Beman Dawes, David Abrahams, 1999-2001.</p> <p>Copyright &copy; Beman Dawes, David Abrahams, 1999-2001.</p>
<p>Copyright &copy; Daniel Frey, 2002-2008.</p> <p>Copyright &copy; Daniel Frey, 2002-2004.</p>
<p>Use, modification, and distribution is subject to the Boost Software <p>Use, modification, and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file License, Version 1.0. (See accompanying file
<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at

View File

@ -7,7 +7,6 @@
// See http://www.boost.org/libs/utility for documentation. // See http://www.boost.org/libs/utility for documentation.
// Revision History // Revision History
// 03 Apr 08 Added convertible_to_bool (Daniel Frey)
// 01 Oct 01 Added tests for "left" operators // 01 Oct 01 Added tests for "left" operators
// and new grouped operators. (Helmut Zeisel) // and new grouped operators. (Helmut Zeisel)
// 20 May 01 Output progress messages. Added tests for new operator // 20 May 01 Output progress messages. Added tests for new operator
@ -44,23 +43,6 @@ namespace
unsigned char true_value(unsigned char x) { return x; } unsigned char true_value(unsigned char x) { return x; }
unsigned short true_value(unsigned short x) { return x; } unsigned short true_value(unsigned short x) { return x; }
// verify the minimum requirements for some operators
class convertible_to_bool
{
private:
bool _value;
typedef bool convertible_to_bool::*unspecified_bool_type;
void operator!() const;
public:
convertible_to_bool( const bool value ) : _value( value ) {}
operator unspecified_bool_type() const
{ return _value ? &convertible_to_bool::_value : 0; }
};
// The use of operators<> here tended to obscure // The use of operators<> here tended to obscure
// interactions with certain compiler bugs // interactions with certain compiler bugs
template <class T> template <class T>
@ -72,10 +54,8 @@ namespace
explicit Wrapped1( T v = T() ) : _value(v) {} explicit Wrapped1( T v = T() ) : _value(v) {}
T value() const { return _value; } T value() const { return _value; }
convertible_to_bool operator<(const Wrapped1& x) const bool operator<(const Wrapped1& x) const { return _value < x._value; }
{ return _value < x._value; } bool operator==(const Wrapped1& x) const { return _value == x._value; }
convertible_to_bool operator==(const Wrapped1& x) const
{ return _value == x._value; }
Wrapped1& operator+=(const Wrapped1& x) Wrapped1& operator+=(const Wrapped1& x)
{ _value += x._value; return *this; } { _value += x._value; return *this; }
@ -117,10 +97,8 @@ namespace
explicit Wrapped2( T v = T() ) : _value(v) {} explicit Wrapped2( T v = T() ) : _value(v) {}
T value() const { return _value; } T value() const { return _value; }
convertible_to_bool operator<(const Wrapped2& x) const bool operator<(const Wrapped2& x) const { return _value < x._value; }
{ return _value < x._value; } bool operator==(const Wrapped2& x) const { return _value == x._value; }
convertible_to_bool operator==(const Wrapped2& x) const
{ return _value == x._value; }
Wrapped2& operator+=(const Wrapped2& x) Wrapped2& operator+=(const Wrapped2& x)
{ _value += x._value; return *this; } { _value += x._value; return *this; }
@ -145,13 +123,9 @@ namespace
Wrapped2& operator++() { ++_value; return *this; } Wrapped2& operator++() { ++_value; return *this; }
Wrapped2& operator--() { --_value; return *this; } Wrapped2& operator--() { --_value; return *this; }
convertible_to_bool operator<(U u) const bool operator<(U u) const { return _value < u; }
{ return _value < u; } bool operator>(U u) const { return _value > u; }
convertible_to_bool operator>(U u) const bool operator==(U u) const { return _value == u; }
{ return _value > u; }
convertible_to_bool operator==(U u) const
{ return _value == u; }
Wrapped2& operator+=(U u) { _value += u; return *this; } Wrapped2& operator+=(U u) { _value += u; return *this; }
Wrapped2& operator-=(U u) { _value -= u; return *this; } Wrapped2& operator-=(U u) { _value -= u; return *this; }
Wrapped2& operator*=(U u) { _value *= u; return *this; } Wrapped2& operator*=(U u) { _value *= u; return *this; }
@ -179,8 +153,7 @@ namespace
explicit Wrapped3( T v = T() ) : _value(v) {} explicit Wrapped3( T v = T() ) : _value(v) {}
T value() const { return _value; } T value() const { return _value; }
convertible_to_bool operator<(const Wrapped3& x) const bool operator<(const Wrapped3& x) const { return _value < x._value; }
{ return _value < x._value; }
private: private:
T _value; T _value;
@ -201,13 +174,10 @@ namespace
explicit Wrapped4( T v = T() ) : _value(v) {} explicit Wrapped4( T v = T() ) : _value(v) {}
T value() const { return _value; } T value() const { return _value; }
convertible_to_bool operator<(const Wrapped4& x) const bool operator<(const Wrapped4& x) const { return _value < x._value; }
{ return _value < x._value; }
convertible_to_bool operator<(U u) const bool operator<(U u) const { return _value < u; }
{ return _value < u; } bool operator>(U u) const { return _value > u; }
convertible_to_bool operator>(U u) const
{ return _value > u; }
private: private:
T _value; T _value;
@ -228,18 +198,11 @@ namespace
Wrapped5(U u) : _value(u) {} Wrapped5(U u) : _value(u) {}
T value() const { return _value; } T value() const { return _value; }
bool operator<(const Wrapped5& x) const { return _value < x._value; }
convertible_to_bool operator<(const Wrapped5& x) const bool operator<(U u) const { return _value < u; }
{ return _value < x._value; } bool operator>(U u) const { return _value > u; }
convertible_to_bool operator<(U u) const bool operator==(const Wrapped5& u) const { return _value == u._value; }
{ return _value < u; } bool operator==(U u) const { return _value == u; }
convertible_to_bool operator>(U u) const
{ return _value > u; }
convertible_to_bool operator==(const Wrapped5& u) const
{ return _value == u._value; }
convertible_to_bool operator==(U u) const
{ return _value == u; }
Wrapped5& operator/=(const Wrapped5& u) { _value /= u._value; return *this;} Wrapped5& operator/=(const Wrapped5& u) { _value /= u._value; return *this;}
Wrapped5& operator/=(U u) { _value /= u; return *this;} Wrapped5& operator/=(U u) { _value /= u; return *this;}
Wrapped5& operator*=(const Wrapped5& u) { _value *= u._value; return *this;} Wrapped5& operator*=(const Wrapped5& u) { _value *= u._value; return *this;}
@ -258,8 +221,8 @@ namespace
// U must be convertible to T // U must be convertible to T
template <class T, class U> template <class T, class U>
class Wrapped6 class Wrapped6
: boost::ordered_euclidean_ring_operators2<Wrapped6<T, U>, U> : boost::ordered_euclidian_ring_operators2<Wrapped6<T, U>, U>
, boost::ordered_euclidean_ring_operators1<Wrapped6<T, U> > , boost::ordered_euclidian_ring_operators1<Wrapped6<T, U> >
{ {
public: public:
explicit Wrapped6( T v = T() ) : _value(v) {} explicit Wrapped6( T v = T() ) : _value(v) {}
@ -268,18 +231,11 @@ namespace
Wrapped6(U u) : _value(u) {} Wrapped6(U u) : _value(u) {}
T value() const { return _value; } T value() const { return _value; }
bool operator<(const Wrapped6& x) const { return _value < x._value; }
convertible_to_bool operator<(const Wrapped6& x) const bool operator<(U u) const { return _value < u; }
{ return _value < x._value; } bool operator>(U u) const { return _value > u; }
convertible_to_bool operator<(U u) const bool operator==(const Wrapped6& u) const { return _value == u._value; }
{ return _value < u; } bool operator==(U u) const { return _value == u; }
convertible_to_bool operator>(U u) const
{ return _value > u; }
convertible_to_bool operator==(const Wrapped6& u) const
{ return _value == u._value; }
convertible_to_bool operator==(U u) const
{ return _value == u; }
Wrapped6& operator%=(const Wrapped6& u) { _value %= u._value; return *this;} Wrapped6& operator%=(const Wrapped6& u) { _value %= u._value; return *this;}
Wrapped6& operator%=(U u) { _value %= u; return *this;} Wrapped6& operator%=(U u) { _value %= u; return *this;}
Wrapped6& operator/=(const Wrapped6& u) { _value /= u._value; return *this;} Wrapped6& operator/=(const Wrapped6& u) { _value /= u._value; return *this;}
@ -320,10 +276,10 @@ namespace
template <class X1, class Y1, class X2, class Y2> template <class X1, class Y1, class X2, class Y2>
void test_less_than_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) void test_less_than_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
{ {
BOOST_CHECK( static_cast<bool>(x1 < y1) == static_cast<bool>(x2 < y2) ); BOOST_CHECK( (x1 < y1) == (x2 < y2) );
BOOST_CHECK( static_cast<bool>(x1 <= y1) == static_cast<bool>(x2 <= y2) ); BOOST_CHECK( (x1 <= y1) == (x2 <= y2) );
BOOST_CHECK( static_cast<bool>(x1 >= y1) == static_cast<bool>(x2 >= y2) ); BOOST_CHECK( (x1 >= y1) == (x2 >= y2) );
BOOST_CHECK( static_cast<bool>(x1 > y1) == static_cast<bool>(x2 > y2) ); BOOST_CHECK( (x1 > y1) == (x2 > y2) );
} }
template <class X1, class Y1, class X2, class Y2> template <class X1, class Y1, class X2, class Y2>
@ -337,8 +293,8 @@ namespace
template <class X1, class Y1, class X2, class Y2> template <class X1, class Y1, class X2, class Y2>
void test_equality_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) void test_equality_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
{ {
BOOST_CHECK( static_cast<bool>(x1 == y1) == static_cast<bool>(x2 == y2) ); BOOST_CHECK( (x1 == y1) == (x2 == y2) );
BOOST_CHECK( static_cast<bool>(x1 != y1) == static_cast<bool>(x2 != y2) ); BOOST_CHECK( (x1 != y1) == (x2 != y2) );
} }
template <class X1, class Y1, class X2, class Y2> template <class X1, class Y1, class X2, class Y2>
@ -658,14 +614,14 @@ test_main( int , char * [] )
PRIVATE_EXPR_TEST( (i = i2), (i.value() == 2) ); PRIVATE_EXPR_TEST( (i = i2), (i.value() == 2) );
BOOST_CHECK( static_cast<bool>(i2 == i) ); BOOST_CHECK( i2 == i );
BOOST_CHECK( static_cast<bool>(i1 != i2) ); BOOST_CHECK( i1 != i2 );
BOOST_CHECK( static_cast<bool>(i1 < i2) ); BOOST_CHECK( i1 < i2 );
BOOST_CHECK( static_cast<bool>(i1 <= i2) ); BOOST_CHECK( i1 <= i2 );
BOOST_CHECK( static_cast<bool>(i <= i2) ); BOOST_CHECK( i <= i2 );
BOOST_CHECK( static_cast<bool>(i2 > i1) ); BOOST_CHECK( i2 > i1 );
BOOST_CHECK( static_cast<bool>(i2 >= i1) ); BOOST_CHECK( i2 >= i1 );
BOOST_CHECK( static_cast<bool>(i2 >= i) ); BOOST_CHECK( i2 >= i );
PRIVATE_EXPR_TEST( (i = i1 + i2), (i.value() == 3) ); PRIVATE_EXPR_TEST( (i = i1 + i2), (i.value() == 3) );
PRIVATE_EXPR_TEST( (i = i + i2), (i.value() == 5) ); PRIVATE_EXPR_TEST( (i = i + i2), (i.value() == 5) );
@ -697,78 +653,78 @@ test_main( int , char * [] )
PRIVATE_EXPR_TEST( (j = j2), (j.value() == 2) ); PRIVATE_EXPR_TEST( (j = j2), (j.value() == 2) );
BOOST_CHECK( static_cast<bool>(j2 == j) ); BOOST_CHECK( j2 == j );
BOOST_CHECK( static_cast<bool>(2 == j) ); BOOST_CHECK( 2 == j );
BOOST_CHECK( static_cast<bool>(j2 == 2) ); BOOST_CHECK( j2 == 2 );
BOOST_CHECK( static_cast<bool>(j == j2) ); BOOST_CHECK( j == j2 );
BOOST_CHECK( static_cast<bool>(j1 != j2) ); BOOST_CHECK( j1 != j2 );
BOOST_CHECK( static_cast<bool>(j1 != 2) ); BOOST_CHECK( j1 != 2 );
BOOST_CHECK( static_cast<bool>(1 != j2) ); BOOST_CHECK( 1 != j2 );
BOOST_CHECK( static_cast<bool>(j1 < j2) ); BOOST_CHECK( j1 < j2 );
BOOST_CHECK( static_cast<bool>(1 < j2) ); BOOST_CHECK( 1 < j2 );
BOOST_CHECK( static_cast<bool>(j1 < 2) ); BOOST_CHECK( j1 < 2 );
BOOST_CHECK( static_cast<bool>(j1 <= j2) ); BOOST_CHECK( j1 <= j2 );
BOOST_CHECK( static_cast<bool>(1 <= j2) ); BOOST_CHECK( 1 <= j2 );
BOOST_CHECK( static_cast<bool>(j1 <= j) ); BOOST_CHECK( j1 <= j );
BOOST_CHECK( static_cast<bool>(j <= j2) ); BOOST_CHECK( j <= j2 );
BOOST_CHECK( static_cast<bool>(2 <= j2) ); BOOST_CHECK( 2 <= j2 );
BOOST_CHECK( static_cast<bool>(j <= 2) ); BOOST_CHECK( j <= 2 );
BOOST_CHECK( static_cast<bool>(j2 > j1) ); BOOST_CHECK( j2 > j1 );
BOOST_CHECK( static_cast<bool>(2 > j1) ); BOOST_CHECK( 2 > j1 );
BOOST_CHECK( static_cast<bool>(j2 > 1) ); BOOST_CHECK( j2 > 1 );
BOOST_CHECK( static_cast<bool>(j2 >= j1) ); BOOST_CHECK( j2 >= j1 );
BOOST_CHECK( static_cast<bool>(2 >= j1) ); BOOST_CHECK( 2 >= j1 );
BOOST_CHECK( static_cast<bool>(j2 >= 1) ); BOOST_CHECK( j2 >= 1 );
BOOST_CHECK( static_cast<bool>(j2 >= j) ); BOOST_CHECK( j2 >= j );
BOOST_CHECK( static_cast<bool>(2 >= j) ); BOOST_CHECK( 2 >= j );
BOOST_CHECK( static_cast<bool>(j2 >= 2) ); BOOST_CHECK( j2 >= 2 );
BOOST_CHECK( static_cast<bool>((j1 + 2) == 3) ); BOOST_CHECK( (j1 + 2) == 3 );
BOOST_CHECK( static_cast<bool>((1 + j2) == 3) ); BOOST_CHECK( (1 + j2) == 3 );
PRIVATE_EXPR_TEST( (j = j1 + j2), (j.value() == 3) ); PRIVATE_EXPR_TEST( (j = j1 + j2), (j.value() == 3) );
BOOST_CHECK( static_cast<bool>((j + 2) == 5) ); BOOST_CHECK( (j + 2) == 5 );
BOOST_CHECK( static_cast<bool>((3 + j2) == 5) ); BOOST_CHECK( (3 + j2) == 5 );
PRIVATE_EXPR_TEST( (j = j + j2), (j.value() == 5) ); PRIVATE_EXPR_TEST( (j = j + j2), (j.value() == 5) );
BOOST_CHECK( static_cast<bool>((j - 1) == 4) ); BOOST_CHECK( (j - 1) == 4 );
PRIVATE_EXPR_TEST( (j = j - j1), (j.value() == 4) ); PRIVATE_EXPR_TEST( (j = j - j1), (j.value() == 4) );
BOOST_CHECK( static_cast<bool>((j * 2) == 8) ); BOOST_CHECK( (j * 2) == 8 );
BOOST_CHECK( static_cast<bool>((4 * j2) == 8) ); BOOST_CHECK( (4 * j2) == 8 );
PRIVATE_EXPR_TEST( (j = j * j2), (j.value() == 8) ); PRIVATE_EXPR_TEST( (j = j * j2), (j.value() == 8) );
BOOST_CHECK( static_cast<bool>((j / 2) == 4) ); BOOST_CHECK( (j / 2) == 4 );
PRIVATE_EXPR_TEST( (j = j / j2), (j.value() == 4) ); PRIVATE_EXPR_TEST( (j = j / j2), (j.value() == 4) );
BOOST_CHECK( static_cast<bool>((j % 3) == 1) ); BOOST_CHECK( (j % 3) == 1 );
PRIVATE_EXPR_TEST( (j = j % ( j - j1 )), (j.value() == 1) ); PRIVATE_EXPR_TEST( (j = j % ( j - j1 )), (j.value() == 1) );
PRIVATE_EXPR_TEST( (j = j2 + j2), (j.value() == 4) ); PRIVATE_EXPR_TEST( (j = j2 + j2), (j.value() == 4) );
BOOST_CHECK( static_cast<bool>((1 | j2 | j) == 7) ); BOOST_CHECK( (1 | j2 | j) == 7 );
BOOST_CHECK( static_cast<bool>((j1 | 2 | j) == 7) ); BOOST_CHECK( (j1 | 2 | j) == 7 );
BOOST_CHECK( static_cast<bool>((j1 | j2 | 4) == 7) ); BOOST_CHECK( (j1 | j2 | 4) == 7 );
PRIVATE_EXPR_TEST( (j = j1 | j2 | j), (j.value() == 7) ); PRIVATE_EXPR_TEST( (j = j1 | j2 | j), (j.value() == 7) );
BOOST_CHECK( static_cast<bool>((7 & j2) == 2) ); BOOST_CHECK( (7 & j2) == 2 );
BOOST_CHECK( static_cast<bool>((j & 2) == 2) ); BOOST_CHECK( (j & 2) == 2 );
PRIVATE_EXPR_TEST( (j = j & j2), (j.value() == 2) ); PRIVATE_EXPR_TEST( (j = j & j2), (j.value() == 2) );
PRIVATE_EXPR_TEST( (j = j | j1), (j.value() == 3) ); PRIVATE_EXPR_TEST( (j = j | j1), (j.value() == 3) );
BOOST_CHECK( static_cast<bool>((3 ^ j1) == 2) ); BOOST_CHECK( (3 ^ j1) == 2 );
BOOST_CHECK( static_cast<bool>((j ^ 1) == 2) ); BOOST_CHECK( (j ^ 1) == 2 );
PRIVATE_EXPR_TEST( (j = j ^ j1), (j.value() == 2) ); PRIVATE_EXPR_TEST( (j = j ^ j1), (j.value() == 2) );
PRIVATE_EXPR_TEST( (j = ( j + j1 ) * ( j2 | j1 )), (j.value() == 9) ); PRIVATE_EXPR_TEST( (j = ( j + j1 ) * ( j2 | j1 )), (j.value() == 9) );
BOOST_CHECK( static_cast<bool>((j1 << 2) == 4) ); BOOST_CHECK( (j1 << 2) == 4 );
BOOST_CHECK( static_cast<bool>((j2 << 1) == 4) ); BOOST_CHECK( (j2 << 1) == 4 );
PRIVATE_EXPR_TEST( (j = j1 << j2), (j.value() == 4) ); PRIVATE_EXPR_TEST( (j = j1 << j2), (j.value() == 4) );
BOOST_CHECK( static_cast<bool>((j >> 2) == 1) ); BOOST_CHECK( (j >> 2) == 1 );
BOOST_CHECK( static_cast<bool>((j2 >> 1) == 1) ); BOOST_CHECK( (j2 >> 1) == 1 );
PRIVATE_EXPR_TEST( (j = j2 >> j1), (j.value() == 1) ); PRIVATE_EXPR_TEST( (j = j2 >> j1), (j.value() == 1) );
cout << "Performed tests on MyLong objects.\n"; cout << "Performed tests on MyLong objects.\n";
@ -785,14 +741,14 @@ test_main( int , char * [] )
PRIVATE_EXPR_TEST( (k = k2), (k.value() == 2) ); PRIVATE_EXPR_TEST( (k = k2), (k.value() == 2) );
BOOST_CHECK( static_cast<bool>(k2 == k) ); BOOST_CHECK( k2 == k );
BOOST_CHECK( static_cast<bool>(k1 != k2) ); BOOST_CHECK( k1 != k2 );
BOOST_CHECK( static_cast<bool>(k1 < k2) ); BOOST_CHECK( k1 < k2 );
BOOST_CHECK( static_cast<bool>(k1 <= k2) ); BOOST_CHECK( k1 <= k2 );
BOOST_CHECK( static_cast<bool>(k <= k2) ); BOOST_CHECK( k <= k2 );
BOOST_CHECK( static_cast<bool>(k2 > k1) ); BOOST_CHECK( k2 > k1 );
BOOST_CHECK( static_cast<bool>(k2 >= k1) ); BOOST_CHECK( k2 >= k1 );
BOOST_CHECK( static_cast<bool>(k2 >= k) ); BOOST_CHECK( k2 >= k );
cout << "Performed tests on MyChar objects.\n"; cout << "Performed tests on MyChar objects.\n";
@ -808,31 +764,31 @@ test_main( int , char * [] )
PRIVATE_EXPR_TEST( (l = l2), (l.value() == 2) ); PRIVATE_EXPR_TEST( (l = l2), (l.value() == 2) );
BOOST_CHECK( static_cast<bool>(l2 == l) ); BOOST_CHECK( l2 == l );
BOOST_CHECK( static_cast<bool>(2 == l) ); BOOST_CHECK( 2 == l );
BOOST_CHECK( static_cast<bool>(l2 == 2) ); BOOST_CHECK( l2 == 2 );
BOOST_CHECK( static_cast<bool>(l == l2) ); BOOST_CHECK( l == l2 );
BOOST_CHECK( static_cast<bool>(l1 != l2) ); BOOST_CHECK( l1 != l2 );
BOOST_CHECK( static_cast<bool>(l1 != 2) ); BOOST_CHECK( l1 != 2 );
BOOST_CHECK( static_cast<bool>(1 != l2) ); BOOST_CHECK( 1 != l2 );
BOOST_CHECK( static_cast<bool>(l1 < l2) ); BOOST_CHECK( l1 < l2 );
BOOST_CHECK( static_cast<bool>(1 < l2) ); BOOST_CHECK( 1 < l2 );
BOOST_CHECK( static_cast<bool>(l1 < 2) ); BOOST_CHECK( l1 < 2 );
BOOST_CHECK( static_cast<bool>(l1 <= l2) ); BOOST_CHECK( l1 <= l2 );
BOOST_CHECK( static_cast<bool>(1 <= l2) ); BOOST_CHECK( 1 <= l2 );
BOOST_CHECK( static_cast<bool>(l1 <= l) ); BOOST_CHECK( l1 <= l );
BOOST_CHECK( static_cast<bool>(l <= l2) ); BOOST_CHECK( l <= l2 );
BOOST_CHECK( static_cast<bool>(2 <= l2) ); BOOST_CHECK( 2 <= l2 );
BOOST_CHECK( static_cast<bool>(l <= 2) ); BOOST_CHECK( l <= 2 );
BOOST_CHECK( static_cast<bool>(l2 > l1) ); BOOST_CHECK( l2 > l1 );
BOOST_CHECK( static_cast<bool>(2 > l1) ); BOOST_CHECK( 2 > l1 );
BOOST_CHECK( static_cast<bool>(l2 > 1) ); BOOST_CHECK( l2 > 1 );
BOOST_CHECK( static_cast<bool>(l2 >= l1) ); BOOST_CHECK( l2 >= l1 );
BOOST_CHECK( static_cast<bool>(2 >= l1) ); BOOST_CHECK( 2 >= l1 );
BOOST_CHECK( static_cast<bool>(l2 >= 1) ); BOOST_CHECK( l2 >= 1 );
BOOST_CHECK( static_cast<bool>(l2 >= l) ); BOOST_CHECK( l2 >= l );
BOOST_CHECK( static_cast<bool>(2 >= l) ); BOOST_CHECK( 2 >= l );
BOOST_CHECK( static_cast<bool>(l2 >= 2) ); BOOST_CHECK( l2 >= 2 );
cout << "Performed tests on MyShort objects.\n"; cout << "Performed tests on MyShort objects.\n";
@ -851,37 +807,37 @@ test_main( int , char * [] )
PRIVATE_EXPR_TEST( (di = di2), (di.value() == 2) ); PRIVATE_EXPR_TEST( (di = di2), (di.value() == 2) );
BOOST_CHECK( static_cast<bool>(di2 == di) ); BOOST_CHECK( di2 == di );
BOOST_CHECK( static_cast<bool>(2 == di) ); BOOST_CHECK( 2 == di );
BOOST_CHECK( static_cast<bool>(di == 2) ); BOOST_CHECK( di == 2 );
BOOST_CHECK( static_cast<bool>(di1 < di2) ); BOOST_CHECK( di1 < di2 );
BOOST_CHECK( static_cast<bool>(1 < di2) ); BOOST_CHECK( 1 < di2 );
BOOST_CHECK( static_cast<bool>(di1 <= di2) ); BOOST_CHECK( di1 <= di2 );
BOOST_CHECK( static_cast<bool>(1 <= di2) ); BOOST_CHECK( 1 <= di2 );
BOOST_CHECK( static_cast<bool>(di2 > di1) ); BOOST_CHECK( di2 > di1 );
BOOST_CHECK( static_cast<bool>(di2 > 1) ); BOOST_CHECK( di2 > 1 );
BOOST_CHECK( static_cast<bool>(di2 >= di1) ); BOOST_CHECK( di2 >= di1 );
BOOST_CHECK( static_cast<bool>(di2 >= 1) ); BOOST_CHECK( di2 >= 1 );
BOOST_CHECK( static_cast<bool>(di1 / di2 == half) ); BOOST_CHECK( di1 / di2 == half );
BOOST_CHECK( static_cast<bool>(di1 / 2 == half) ); BOOST_CHECK( di1 / 2 == half );
BOOST_CHECK( static_cast<bool>(1 / di2 == half) ); BOOST_CHECK( 1 / di2 == half );
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp/=2) == half) ); PRIVATE_EXPR_TEST( (tmp=di1), ((tmp/=2) == half) );
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp/=di2) == half) ); PRIVATE_EXPR_TEST( (tmp=di1), ((tmp/=di2) == half) );
BOOST_CHECK( static_cast<bool>(di1 * di2 == di2) ); BOOST_CHECK( di1 * di2 == di2 );
BOOST_CHECK( static_cast<bool>(di1 * 2 == di2) ); BOOST_CHECK( di1 * 2 == di2 );
BOOST_CHECK( static_cast<bool>(1 * di2 == di2) ); BOOST_CHECK( 1 * di2 == di2 );
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp*=2) == di2) ); PRIVATE_EXPR_TEST( (tmp=di1), ((tmp*=2) == di2) );
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp*=di2) == di2) ); PRIVATE_EXPR_TEST( (tmp=di1), ((tmp*=di2) == di2) );
BOOST_CHECK( static_cast<bool>(di2 - di1 == di1) ); BOOST_CHECK( di2 - di1 == di1 );
BOOST_CHECK( static_cast<bool>(di2 - 1 == di1) ); BOOST_CHECK( di2 - 1 == di1 );
BOOST_CHECK( static_cast<bool>(2 - di1 == di1) ); BOOST_CHECK( 2 - di1 == di1 );
PRIVATE_EXPR_TEST( (tmp=di2), static_cast<bool>((tmp-=1) == di1) ); PRIVATE_EXPR_TEST( (tmp=di2), ((tmp-=1) == di1) );
PRIVATE_EXPR_TEST( (tmp=di2), static_cast<bool>((tmp-=di1) == di1) ); PRIVATE_EXPR_TEST( (tmp=di2), ((tmp-=di1) == di1) );
BOOST_CHECK( static_cast<bool>(di1 + di1 == di2) ); BOOST_CHECK( di1 + di1 == di2 );
BOOST_CHECK( static_cast<bool>(di1 + 1 == di2) ); BOOST_CHECK( di1 + 1 == di2 );
BOOST_CHECK( static_cast<bool>(1 + di1 == di2) ); BOOST_CHECK( 1 + di1 == di2 );
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp+=1) == di2) ); PRIVATE_EXPR_TEST( (tmp=di1), ((tmp+=1) == di2) );
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp+=di1) == di2) ); PRIVATE_EXPR_TEST( (tmp=di1), ((tmp+=di1) == di2) );
cout << "Performed tests on MyDoubleInt objects.\n"; cout << "Performed tests on MyDoubleInt objects.\n";
@ -898,42 +854,42 @@ test_main( int , char * [] )
PRIVATE_EXPR_TEST( (li = li2), (li.value() == 2) ); PRIVATE_EXPR_TEST( (li = li2), (li.value() == 2) );
BOOST_CHECK( static_cast<bool>(li2 == li) ); BOOST_CHECK( li2 == li );
BOOST_CHECK( static_cast<bool>(2 == li) ); BOOST_CHECK( 2 == li );
BOOST_CHECK( static_cast<bool>(li == 2) ); BOOST_CHECK( li == 2 );
BOOST_CHECK( static_cast<bool>(li1 < li2) ); BOOST_CHECK( li1 < li2 );
BOOST_CHECK( static_cast<bool>(1 < li2) ); BOOST_CHECK( 1 < li2 );
BOOST_CHECK( static_cast<bool>(li1 <= li2) ); BOOST_CHECK( li1 <= li2 );
BOOST_CHECK( static_cast<bool>(1 <= li2) ); BOOST_CHECK( 1 <= li2 );
BOOST_CHECK( static_cast<bool>(li2 > li1) ); BOOST_CHECK( li2 > li1 );
BOOST_CHECK( static_cast<bool>(li2 > 1) ); BOOST_CHECK( li2 > 1 );
BOOST_CHECK( static_cast<bool>(li2 >= li1) ); BOOST_CHECK( li2 >= li1 );
BOOST_CHECK( static_cast<bool>(li2 >= 1) ); BOOST_CHECK( li2 >= 1 );
BOOST_CHECK( static_cast<bool>(li1 % li2 == li1) ); BOOST_CHECK( li1 % li2 == li1 );
BOOST_CHECK( static_cast<bool>(li1 % 2 == li1) ); BOOST_CHECK( li1 % 2 == li1 );
BOOST_CHECK( static_cast<bool>(1 % li2 == li1) ); BOOST_CHECK( 1 % li2 == li1 );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2%=2) == li1) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2%=2) == li1) );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2%=li2) == li1) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2%=li2) == li1) );
BOOST_CHECK( static_cast<bool>(li1 / li2 == 0) ); BOOST_CHECK( li1 / li2 == 0 );
BOOST_CHECK( static_cast<bool>(li1 / 2 == 0) ); BOOST_CHECK( li1 / 2 == 0 );
BOOST_CHECK( static_cast<bool>(1 / li2 == 0) ); BOOST_CHECK( 1 / li2 == 0 );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2/=2) == 0) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2/=2) == 0) );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2/=li2) == 0) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2/=li2) == 0) );
BOOST_CHECK( static_cast<bool>(li1 * li2 == li2) ); BOOST_CHECK( li1 * li2 == li2 );
BOOST_CHECK( static_cast<bool>(li1 * 2 == li2) ); BOOST_CHECK( li1 * 2 == li2 );
BOOST_CHECK( static_cast<bool>(1 * li2 == li2) ); BOOST_CHECK( 1 * li2 == li2 );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2*=2) == li2) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2*=2) == li2) );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2*=li2) == li2) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2*=li2) == li2) );
BOOST_CHECK( static_cast<bool>(li2 - li1 == li1) ); BOOST_CHECK( li2 - li1 == li1 );
BOOST_CHECK( static_cast<bool>(li2 - 1 == li1) ); BOOST_CHECK( li2 - 1 == li1 );
BOOST_CHECK( static_cast<bool>(2 - li1 == li1) ); BOOST_CHECK( 2 - li1 == li1 );
PRIVATE_EXPR_TEST( (tmp2=li2), static_cast<bool>((tmp2-=1) == li1) ); PRIVATE_EXPR_TEST( (tmp2=li2), ((tmp2-=1) == li1) );
PRIVATE_EXPR_TEST( (tmp2=li2), static_cast<bool>((tmp2-=li1) == li1) ); PRIVATE_EXPR_TEST( (tmp2=li2), ((tmp2-=li1) == li1) );
BOOST_CHECK( static_cast<bool>(li1 + li1 == li2) ); BOOST_CHECK( li1 + li1 == li2 );
BOOST_CHECK( static_cast<bool>(li1 + 1 == li2) ); BOOST_CHECK( li1 + 1 == li2 );
BOOST_CHECK( static_cast<bool>(1 + li1 == li2) ); BOOST_CHECK( 1 + li1 == li2 );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2+=1) == li2) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2+=1) == li2) );
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2+=li1) == li2) ); PRIVATE_EXPR_TEST( (tmp2=li1), ((tmp2+=li1) == li2) );
cout << "Performed tests on MyLongInt objects.\n"; cout << "Performed tests on MyLongInt objects.\n";

View File

@ -68,54 +68,11 @@ struct ref_wrapper
} }
}; };
struct copy_counter {
static int count_;
copy_counter(copy_counter const& other) {
++count_;
}
copy_counter() {}
static void reset() { count_ = 0; }
static int count() { return copy_counter::count_; }
};
int copy_counter::count_ = 0;
} // namespace unnamed } // namespace unnamed
template <class T>
void do_unwrap(T t) {
/* typename unwrap_reference<T>::type& lt = */
unwrap_ref(t);
}
void unwrap_test() {
int i = 3;
const int ci = 2;
do_unwrap(i);
do_unwrap(ci);
do_unwrap(ref(i));
do_unwrap(cref(ci));
do_unwrap(ref(ci));
copy_counter cc;
BOOST_CHECK(cc.count() == 0);
do_unwrap(cc);
do_unwrap(ref(cc));
do_unwrap(cref(cc));
BOOST_CHECK(cc.count() == 1);
BOOST_CHECK(unwrap_ref(ref(cc)).count() == 1);
}
int test_main(int, char * []) int test_main(int, char * [])
{ {
ref_wrapper<int>::test(1); ref_wrapper<int>::test(1);
ref_wrapper<int const>::test(1); ref_wrapper<int const>::test(1);
unwrap_test();
return 0; return 0;
} }

View File

@ -11,101 +11,35 @@
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp> #include <boost/type_traits/is_same.hpp>
struct int_result_type struct int_result_type { typedef int result_type; };
{
typedef int result_type;
result_type operator()(float);
};
struct int_result_of struct int_result_of
{ {
template<typename F> struct result { typedef int type; }; template<typename F> struct result { typedef int type; };
result<int_result_of(double)>::type operator()(double);
result<const int_result_of(double)>::type operator()(double) const;
result<int_result_of()>::type operator()();
result<volatile int_result_of()>::type operator()() volatile;
}; };
struct int_result_type_and_float_result_of_and_char_return struct int_result_type_and_float_result_of
{ {
typedef int result_type; typedef int result_type;
template<typename F> struct result { typedef float type; }; template<typename F> struct result { typedef float type; };
char operator()(char);
}; };
template<typename T> template<typename T>
struct int_result_type_template struct int_result_type_template { typedef int result_type; };
{
typedef int result_type;
result_type operator()(float);
};
template<typename T> template<typename T>
struct int_result_of_template struct int_result_of_template
{ {
template<typename F> struct result; template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef int type; }; template<typename This, typename That> struct result<This(That)> { typedef int type; };
typename result<int_result_of_template<T>(double)>::type operator()(double);
typename result<const int_result_of_template<T>(double)>::type operator()(double) const;
typename result<int_result_of_template<T>(double)>::type operator()();
typename result<volatile int_result_of_template<T>(double)>::type operator()() volatile;
}; };
template<typename T> template<typename T>
struct int_result_type_and_float_result_of_and_char_return_template struct int_result_type_and_float_result_of_template
{ {
typedef int result_type; typedef int result_type;
template<typename F> struct result; template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef float type; }; template<typename This, typename That> struct result<This(That)> { typedef float type; };
char operator()(char);
};
struct result_of_member_function_template
{
template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef That type; };
template<class T> typename result<result_of_member_function_template(T)>::type operator()(T);
template<typename This, typename That> struct result<const This(That)> { typedef const That type; };
template<class T> typename result<const result_of_member_function_template(T)>::type operator()(T) const;
template<typename This, typename That> struct result<volatile This(That)> { typedef volatile That type; };
template<class T> typename result<volatile result_of_member_function_template(T)>::type operator()(T) volatile;
template<typename This, typename That> struct result<const volatile This(That)> { typedef const volatile That type; };
template<class T> typename result<const volatile result_of_member_function_template(T)>::type operator()(T) const volatile;
template<typename This, typename That> struct result<This(That &, That)> { typedef That & type; };
template<class T> typename result<result_of_member_function_template(T &, T)>::type operator()(T &, T);
template<typename This, typename That> struct result<This(That const &, That)> { typedef That const & type; };
template<class T> typename result<result_of_member_function_template(T const &, T)>::type operator()(T const &, T);
template<typename This, typename That> struct result<This(That volatile &, That)> { typedef That volatile & type; };
template<class T> typename result<result_of_member_function_template(T volatile &, T)>::type operator()(T volatile &, T);
template<typename This, typename That> struct result<This(That const volatile &, That)> { typedef That const volatile & type; };
template<class T> typename result<result_of_member_function_template(T const volatile &, T)>::type operator()(T const volatile &, T);
};
struct no_result_type_or_result_of
{
int operator()(double);
short operator()(double) const;
unsigned int operator()();
unsigned short operator()() volatile;
const unsigned short operator()() const volatile;
};
template<typename T>
struct no_result_type_or_result_of_template
{
int operator()(double);
short operator()(double) const;
unsigned int operator()();
unsigned short operator()() volatile;
const unsigned short operator()() const volatile;
}; };
struct X {}; struct X {};
@ -126,37 +60,16 @@ int main()
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type(float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_type(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(double)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of(double)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of(char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_template<void>(float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_template<void>(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value));
// Prior to decltype, result_of could not deduce the return type
// nullary function objects unless they exposed a result_type.
#if defined(BOOST_HAS_DECLTYPE)
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, int>::value));
#else
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(void)>::type, void>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value)); BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
#endif BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_template<void>(char)>::type, int>::value));
// Prior to decltype, result_of ignored a nested result<> if
// result_type was defined. After decltype, result_of deduces the
// actual return type of the function object, ignoring both
// result<> and result_type.
#if defined(BOOST_HAS_DECLTYPE)
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, char>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, char>::value));
#else
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, int>::value));
#endif
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(char, float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ref(char, float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ref(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr_0()>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ptr_0()>::type, int>::value));
@ -168,31 +81,5 @@ int main()
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(void)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(double)>::type, double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const result_of_member_function_template(double)>::type, const double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const volatile result_of_member_function_template(double)>::type, const volatile double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int &, int)>::type, int &>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int const &, int)>::type, int const &>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value));
typedef int (*pf_t)(int);
BOOST_STATIC_ASSERT((is_same<result_of<pf_t(int)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<pf_t const(int)>::type,int>::value));
#if defined(BOOST_HAS_DECLTYPE)
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(void)>::type, unsigned int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const no_result_type_or_result_of(double)>::type, short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile no_result_type_or_result_of(void)>::type, unsigned short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const volatile no_result_type_or_result_of(void)>::type, const unsigned short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(void)>::type, unsigned int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const no_result_type_or_result_of_template<void>(double)>::type, short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile no_result_type_or_result_of_template<void>(void)>::type, unsigned short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const volatile no_result_type_or_result_of_template<void>(void)>::type, const unsigned short>::value));
#endif
return 0; return 0;
} }

View File

@ -154,13 +154,11 @@ void f() {
...,t<em>N</em>)</code>. The implementation permits ...,t<em>N</em>)</code>. The implementation permits
the type <code>F</code> to be a function pointer, the type <code>F</code> to be a function pointer,
function reference, member function pointer, or class function reference, member function pointer, or class
type.</p> <p>If your compiler does not support type. When <code>F</code> is a class type with a
<code>decltype</code>, then when <code>F</code> is a member type <code>result_type</code>,
class type with a member type <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is T<em>N</em>)&gt;</code> is
<code>F::result_type</code>. When <code>F</code> <code>F::result_type</code>. Otherwise,
does not contain <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is <code>F::result&lt;F(T1, T<em>N</em>)&gt;</code> is <code>F::result&lt;F(T1,
T2, ..., T<em>N</em>)&gt;::type</code> when T2, ..., T<em>N</em>)&gt;::type</code> when

View File

@ -253,7 +253,7 @@ its internal data, prior to constructing the object that it contains.
<h2><a name="val_init"><code>template class value_initialized&lt;T&gt;</code></a></h2> <h2><a name="val_init"><code>template class value_initialized&lt;T&gt;</code></a></h2>
<pre>namespace boost {<br><br>template&lt;class T&gt;<br>class value_initialized<br>{<br> public :<br> value_initialized() : x() {}<br> operator T&amp;() const { return x ; }<br> T&amp; data() const { return x ; }<br> void swap( value_initialized&lt;T&gt;&amp; );<br><br> private :<br> <i>unspecified</i> x ;<br>} ;<br><br>template&lt;class T&gt;<br>T const&amp; get ( value_initialized&lt;T&gt; const&amp; x )<br>{<br> return x.data() ;<br>}<br><br>template&lt;class T&gt;<br>T&amp; get ( value_initialized&lt;T&gt;&amp; x )<br>{<br> return x.data() ;<br>}<br><br>} // namespace boost<br></pre> <pre>namespace boost {<br><br>template&lt;class T&gt;<br>class value_initialized<br>{<br> public :<br> value_initialized() : x() {}<br> operator T&amp;() const { return x ; }<br> T&amp; data() const { return x ; }<br><br> private :<br> <i>unspecified</i> x ;<br>} ;<br><br>template&lt;class T&gt;<br>T const&amp; get ( value_initialized&lt;T&gt; const&amp; x )<br>{<br> return x.data() ;<br>}<br><br>template&lt;class T&gt;<br>T&amp; get ( value_initialized&lt;T&gt;&amp; x )<br>{<br> return x.data() ;<br>}<br><br>} // namespace boost<br></pre>
<p>An object of this template class is a <code>T</code>-wrapper convertible <p>An object of this template class is a <code>T</code>-wrapper convertible
to <code>'T&amp;'</code> whose wrapped object (data member of type <code>T</code>) to <code>'T&amp;'</code> whose wrapped object (data member of type <code>T</code>)
@ -276,10 +276,6 @@ non-member function <code>get()</code>: </p>
<p>Both <code>const</code> and non-<code>const</code> objects can be wrapped. <p>Both <code>const</code> and non-<code>const</code> objects can be wrapped.
Mutable objects can be modified directly from within the wrapper but constant Mutable objects can be modified directly from within the wrapper but constant
objects cannot:</p> objects cannot:</p>
<p>When <code>T</code> is a <em>Swappable</em> type, <code>value_initialized&lt;T&gt;</code>
is swappable as well, by calling its <code>swap</code> member function
as well as by calling <code>boost::swap</code>.</p>
<pre>value_initialized&lt;int&gt; x ; <br>static_cast&lt;int&amp;&gt;(x) = 1 ; // OK<br>get(x) = 1 ; // OK<br><br>value_initialized&lt;int const&gt; y ; <br>static_cast&lt;int&amp;&gt;(y) = 1 ; // ERROR: cannot cast to int&amp;<br>static_cast&lt;int const&amp;&gt;(y) = 1 ; // ERROR: cannot modify a const value<br>get(y) = 1 ; // ERROR: cannot modify a const value</pre> <pre>value_initialized&lt;int&gt; x ; <br>static_cast&lt;int&amp;&gt;(x) = 1 ; // OK<br>get(x) = 1 ; // OK<br><br>value_initialized&lt;int const&gt; y ; <br>static_cast&lt;int&amp;&gt;(y) = 1 ; // ERROR: cannot cast to int&amp;<br>static_cast&lt;int const&amp;&gt;(y) = 1 ; // ERROR: cannot modify a const value<br>get(y) = 1 ; // ERROR: cannot modify a const value</pre>
@ -315,7 +311,7 @@ wrapped object from within a constant wrapper can be avoided if access to
the wrapped object is always performed with the <code>get()</code> idiom:</p> the wrapped object is always performed with the <code>get()</code> idiom:</p>
<pre>value_initialized&lt;int&gt; x ;<br>get(x) = 1 ; // OK<br><br>value_initialized&lt;int const&gt; cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int&gt; const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int const&gt; const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre> <pre>value_initialized&lt;int&gt; x ;<br>get(x) = 1 ; // OK<br><br>value_initialized&lt;int const&gt; cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int&gt; const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int const&gt; const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre>
<h2><a name="initialized_value"><code>initialized_value</code></a></h2> <h2><a name="initialized_value"><code>initialized_value</code></a></h2>
<pre> <pre>
@ -383,7 +379,7 @@ for Boost release version 1.35 (2008), offering a workaround to various compiler
</p> </p>
<hr> <hr>
<p>Revised 28 August 2008</p> <p>Revised 23 May 2008</p>
<p>&copy; Copyright Fernando Cacciola, 2002, 2008.</p> <p>&copy; Copyright Fernando Cacciola, 2002, 2008.</p>
@ -394,4 +390,4 @@ for Boost release version 1.35 (2008), offering a workaround to various compiler
<br> <br>
</body> </body>
</html> </html>

View File

@ -9,7 +9,6 @@
// 21 Ago 2002 (Created) Fernando Cacciola // 21 Ago 2002 (Created) Fernando Cacciola
// 15 Jan 2008 (Added tests regarding compiler issues) Fernando Cacciola, Niels Dekker // 15 Jan 2008 (Added tests regarding compiler issues) Fernando Cacciola, Niels Dekker
// 23 May 2008 (Added tests regarding initialized_value) Niels Dekker // 23 May 2008 (Added tests regarding initialized_value) Niels Dekker
// 21 Ago 2008 (Added swap test) Niels Dekker
#include <cstring> // For memcmp. #include <cstring> // For memcmp.
#include <iostream> #include <iostream>
@ -182,35 +181,6 @@ struct CopyFunctionCallTester
}; };
//
// A struct that allows testing whether its customized swap function is called.
//
struct SwapFunctionCallTester
{
bool is_custom_swap_called;
int data;
SwapFunctionCallTester()
: is_custom_swap_called(false), data(0) {}
SwapFunctionCallTester(const SwapFunctionCallTester & arg)
: is_custom_swap_called(false), data(arg.data) {}
void swap(SwapFunctionCallTester & arg)
{
std::swap(data, arg.data);
is_custom_swap_called = true;
arg.is_custom_swap_called = true;
}
};
void swap(SwapFunctionCallTester & lhs, SwapFunctionCallTester & rhs)
{
lhs.swap(rhs);
}
template<class T> template<class T>
void check_initialized_value ( T const& y ) void check_initialized_value ( T const& y )
{ {
@ -226,7 +196,7 @@ void check_initialized_value( NonPOD const& )
// and this type (NonPOD), because the following statement // and this type (NonPOD), because the following statement
// won't compile on this particular compiler version: // won't compile on this particular compiler version:
// NonPOD initializedValue = boost::initialized_value() ; // NonPOD initializedValue = boost::initialized_value() ;
// //
// This is caused by a compiler bug, that is fixed with a newer version // This is caused by a compiler bug, that is fixed with a newer version
// of the Borland compiler. The Release Notes for Delphi(R) 2007 for // of the Borland compiler. The Release Notes for Delphi(R) 2007 for
// Win32(R) and C++Builder(R) 2007 (http://dn.codegear.com/article/36575) // Win32(R) and C++Builder(R) 2007 (http://dn.codegear.com/article/36575)
@ -353,20 +323,9 @@ int test_main(int, char **)
BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed); BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed);
BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called); BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called);
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester1;
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester2;
get(swapFunctionCallTester1).data = 1;
get(swapFunctionCallTester2).data = 2;
boost::swap(swapFunctionCallTester1, swapFunctionCallTester2);
BOOST_CHECK( get(swapFunctionCallTester1).data == 2 );
BOOST_CHECK( get(swapFunctionCallTester2).data == 1 );
BOOST_CHECK( get(swapFunctionCallTester1).is_custom_swap_called );
BOOST_CHECK( get(swapFunctionCallTester2).is_custom_swap_called );
return 0; return 0;
} }
unsigned int expected_failures = 0; unsigned int expected_failures = 0;