Compare commits

...

30 Commits

Author SHA1 Message Date
f009e6754d Branch at revision 46530
[SVN r46531]
2008-06-19 18:57:10 +00:00
67f3ca090a Fixed value_init test + doc, according to change of boost::initialized_value, revision [45685]
[SVN r45686]
2008-05-23 16:48:10 +00:00
8efae71f4a Changed boost::initialized_value from a class to an instance, to make its use more convenient, as discussed with Fernando.
[SVN r45685]
2008-05-23 16:46:43 +00:00
ad0bcf4a00 result_of implementation that makes use of C++0x decltype, from Daniel Walker. Fixes #862.
[SVN r45256]
2008-05-09 22:08:46 +00:00
f1c86c35c4 Merge in documentation fixes. Apart from the change to optional's documenation
Jamfile, which I included by mistake.

Fixes #1659, #1661, #1684, #1685, 1687, #1690, #1801

I wrote about this at:

http://lists.boost.org/Archives/boost/2008/04/136405.php

Merged revisions 44585-44806 via svnmerge from 
https://svn.boost.org/svn/boost/branches/doc

........
  r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix broken link to vacpp in bjam docs. Refs #1512
........
  r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix broken link to bcpp in bjam docs. Refs #1513
........
  r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  DateTime documentation - Fix a link to the serialization library. Refs #1659
........
  r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix some links in interprocess & intrusive. Refs #1661
........
  r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix some links in the python docs. Refs #1684.
........
  r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Work around a quickbook bug which is affecting the python docs. Refs #1684.
........
  r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix a broken link in the numeric conversion docs. Refs #1685
........
  r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix some links in the optional docs. Refs #1687
........
  r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix link to the hash documentation from bimap. Refs #1690
........
  r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix a typo in the format library. Refs #1801
........
  r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line
  
  Initialise svnmerge.
........
  r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix the lincense url in shared container iterator documentation.
........
  r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix image link in the mpi documentation.
........
  r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix a typo in the spirit docs.
........
  r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844
........
  r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix another typo in spirit docs.
........


[SVN r44807]
2008-04-27 07:39:49 +00:00
a5b85eda07 Fix #1846.
[SVN r44705]
2008-04-21 21:42:29 +00:00
bafe37fdab Boost Exception header compilation tests added.
[SVN r44442]
2008-04-15 21:13:24 +00:00
be50b95508 Added test and fix for "convertible to bool" requirement
[SVN r44151]
2008-04-10 14:38:14 +00:00
96d573d6ca Replaced all occurrences of non-ASCII copyright symbol with '(c)' for people using non-ASCII code pages
[SVN r43992]
2008-04-02 01:42:32 +00:00
2412b864d6 Fix some inspection report issues.
[SVN r43633]
2008-03-15 18:41:51 +00:00
94865eabe6 boost exception
[SVN r43485]
2008-03-04 01:41:17 +00:00
50268d1b29 Tested the assignment of value_initialized<T>, for T being a C-style array. Related to the fix of changeset [43308]
[SVN r43309]
2008-02-18 22:13:21 +00:00
ad9108c1dc Fixed the assignment of value_initialized<T> for T being a C-style array. (The previous version would trigger a compile error in this case.)
[SVN r43308]
2008-02-18 22:11:19 +00:00
691e4b6c34 Link to people pages on the website, as they've been removed from the download.
[SVN r43209]
2008-02-10 14:56:22 +00:00
28596e678d value_init: Removed aligned_storage::address() calls, to improve TR1 compatibility, as confirmed by John Maddock. Added internal helper function, wrapper_address(), as discussed with Fernando.
[SVN r43025]
2008-01-30 22:42:23 +00:00
1beca24dd8 Removed local named variable from value_initialized::operator=, as Fernando Cacciola suggested me to avoid unnecessary named variables.
[SVN r42869]
2008-01-19 20:52:04 +00:00
721764937f value_init_test now works around Borland 5.82 bug ("Error E2015: Ambiguity..." when using initialized_value), that is fixed with a newer compiler version
[SVN r42868]
2008-01-19 20:21:18 +00:00
a511007d0f Added test and documentation for convenience class initialized_value, that was added with changeset [42815]
[SVN r42816]
2008-01-16 09:37:25 +00:00
8ce58b1675 Added convenience class initialized_value, as announced at http://article.gmane.org/gmane.comp.lib.boost.devel/169833
[SVN r42815]
2008-01-16 09:35:12 +00:00
9ed68b8321 value_init doc + test: Added revision date.
[SVN r42798]
2008-01-15 19:53:28 +00:00
79bbf71d0d Minor "beautifications" of value_init documentation, inc. placing references in order of appearance
[SVN r42779]
2008-01-14 21:46:20 +00:00
ac93de7c1b Documented value_init workaround to compiler issues, added new introduction, updated to 2003 edition of C++ Standard -- reviewed by Fernando Cacciola
[SVN r42771]
2008-01-14 18:17:30 +00:00
d731b8e1c5 Added value_init tests, testing copy construction and assignment.
[SVN r42278]
2007-12-24 22:00:37 +00:00
ac1567b3fc value_init now uses aligned_storage::address(), instead of "&x", as recommended by Fernando Cacciola (by mail)
[SVN r42277]
2007-12-24 20:42:16 +00:00
c1fd670480 Reduce header dependencies, from Shunsuke Sogame. Fixes #1535
[SVN r42234]
2007-12-21 21:18:17 +00:00
01274cf6ac value_init.hpp now no longer distinguished between workaround and non-workaround, because many compilers don't do value-initialization well. Fixed copy construction and assignment -- discussed with Fernando Cacciola
[SVN r41942]
2007-12-09 22:49:58 +00:00
8080673977 Added value_init tests if a copy function of T is called when value_initialized<T> is copied -- a case I hadn't thought of before...
[SVN r41919]
2007-12-09 11:53:08 +00:00
a470b591fb Added value_init test for an value_initialized<T> object allocated on the heap.
[SVN r41667]
2007-12-03 21:41:59 +00:00
e1a63495b6 Added missing #include to value_init_test.cpp. (My mistake!)
[SVN r41648]
2007-12-03 18:20:19 +00:00
7300ac83f1 Added value_init test for C style array of bytes
[SVN r41647]
2007-12-03 18:14:37 +00:00
28 changed files with 861 additions and 374 deletions

View File

@ -334,7 +334,7 @@ with the exact pointer type used in <code>switcher</code>'s constructor.</p>
<h3><a name="contributors">Contributors</a></h3>
<dl>
<dt><a href="../../people/ed_brey.htm">Ed Brey</a>
<dt><a href="http://www.boost.org/people/ed_brey.htm">Ed Brey</a>
<dd>Suggested some interface changes.
<dt><a href="http://www.moocat.org">R. Samuel Klatchko</a> (<a
@ -343,7 +343,7 @@ with the exact pointer type used in <code>switcher</code>'s constructor.</p>
<dd>Invented the idiom of how to use a class member for initializing
a base class.
<dt><a href="../../people/dietmar_kuehl.htm">Dietmar Kuehl</a>
<dt><a href="http://www.boost.org/people/dietmar_kuehl.htm">Dietmar Kuehl</a>
<dd>Popularized the base-from-member idiom in his
<a href="http://www.informatik.uni-konstanz.de/~kuehl/c++/iostream/">IOStream
example classes</a>.
@ -353,7 +353,7 @@ with the exact pointer type used in <code>switcher</code>'s constructor.</p>
can be controlled and automated with macros. The implementation uses
the <a href="../preprocessor/index.html">Preprocessor library</a>.
<dt><a href="../../people/daryle_walker.html">Daryle Walker</a>
<dt><a href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>
<dd>Started the library. Contributed the test file <cite><a
href="base_from_member_test.cpp">base_from_member_test.cpp</a></cite>.
</dl>

View File

@ -740,26 +740,16 @@ specialisation).</p>
<p>Revised 01 September 2000</p>
<p><EFBFBD> Copyright boost.org 2000. Permission to copy, use, modify,
sell and distribute this document is granted provided this
copyright notice appears in all copies. This document is provided
&quot;as is&quot; without express or implied warranty, and with
no claim as to its suitability for any purpose.</p>
<p>Based on contributions by Steve Cleary, Beman Dawes, Howard
Hinnant and John Maddock.</p>
<p>Maintained by <a href="mailto:john@johnmaddock.co.uk">John
Maddock</a>, the latest version of this file can be found at <a
href="http://www.boost.org/">www.boost.org</a>, and the boost
discussion list at <a
href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>.</p>
<p>.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>
Copyright 2000 Steve Cleary, Beman Dawes, Howard
Hinnant and John Maddock. <br/>
Use, modification and distribution are subject to the
Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt
or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
http://www.boost.org/LICENSE_1_0.txt
</a>).
</p>
</body>
</html>

View File

@ -366,17 +366,18 @@ David Vandevoorde and Nicolai&nbsp;M. Josuttis.
<EM>C++ Templates: The Complete Guide</EM>.
Addison-Wesley, 2002.</DL>
<hr></hr>
<B>Contributed by:</B> <BR>
Jaakko J&auml;rvi, Jeremiah Willcock and Andrew Lumsdaine<BR>
<hr/>
<p>Copyright Jaakko J&auml;rvi, Jeremiah Willcock and Andrew Lumsdaine<BR>
<EM>{jajarvi|jewillco|lums}@osl.iu.edu</EM><BR>
Indiana University<BR>
Open Systems Lab
Open Systems Lab<br/>
Use, modification and distribution are subject to the
Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt
or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
http://www.boost.org/LICENSE_1_0.txt
</a>).
</p>
<!--HTMLFOOT-->
<!--ENDHTML-->
<!--FOOTER-->

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -153,7 +153,7 @@ int main()
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05 December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
<p><i>Copyright &copy; 2001 <a href=
"../../people/jens_maurer.htm">Jens Maurer</a></i></p>
"http://www.boost.org/people/jens_maurer.htm">Jens Maurer</a></i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or

View File

@ -0,0 +1,13 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_1D94A7C6054E11DB9804B622A1EF5492
#define UUID_1D94A7C6054E11DB9804B622A1EF5492
#include <boost/exception/info_tuple.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/throw_exception.hpp>
#endif

View File

@ -8,6 +8,8 @@
// See http://www.boost.org/libs/utility/operators.htm for documentation.
// Revision History
// 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
// http://svn.boost.org/trac/boost/ticket/979
// 21 Oct 02 Modified implementation of operators to allow compilers with a
@ -124,34 +126,34 @@ namespace boost
template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct less_than_comparable2 : B
{
friend bool operator<=(const T& x, const U& y) { return !(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 !static_cast<bool>(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 !static_cast<bool>(y > x); }
};
template <class T, class B = ::boost::detail::empty_base<T> >
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 !(x < y); }
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 !static_cast<bool>(x < y); }
};
template <class T, class U, class B = ::boost::detail::empty_base<T> >
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 T& y, const U& x) { return !(y == x); }
friend bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
friend bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
};
template <class T, class B = ::boost::detail::empty_base<T> >
struct equality_comparable1 : B
{
friend bool operator!=(const T& x, const T& y) { return !(x == y); }
friend bool operator!=(const T& x, const T& y) { return !static_cast<bool>(x == y); }
};
// A macro which produces "name_2left" from "name".
@ -356,7 +358,7 @@ struct equivalent2 : B
{
friend bool operator==(const T& x, const U& y)
{
return !(x < y) && !(x > y);
return !static_cast<bool>(x < y) && !static_cast<bool>(x > y);
}
};
@ -365,7 +367,7 @@ struct equivalent1 : B
{
friend bool operator==(const T&x, const T&y)
{
return !(x < y) && !(y < x);
return !static_cast<bool>(x < y) && !static_cast<bool>(y < x);
}
};
@ -373,17 +375,17 @@ template <class T, class U, class B = ::boost::detail::empty_base<T> >
struct partially_ordered2 : B
{
friend bool operator<=(const T& x, const U& y)
{ return (x < y) || (x == y); }
{ return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
friend bool operator>=(const T& x, const U& y)
{ return (x > y) || (x == y); }
{ return static_cast<bool>(x > y) || static_cast<bool>(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) || (y == x); }
{ return static_cast<bool>(y > x) || static_cast<bool>(y == x); }
friend bool operator>=(const U& x, const T& y)
{ return (y < x) || (y == x); }
{ return static_cast<bool>(y < x) || static_cast<bool>(y == x); }
};
template <class T, class B = ::boost::detail::empty_base<T> >
@ -392,9 +394,9 @@ struct partially_ordered1 : B
friend bool operator>(const T& x, const T& y)
{ return y < x; }
friend bool operator<=(const T& x, const T& y)
{ return (x < y) || (x == y); }
{ return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
friend bool operator>=(const T& x, const T& y)
{ return (y < x) || (x == y); }
{ return static_cast<bool>(y < x) || static_cast<bool>(x == y); }
};
// Combined operator classes (contributed by Daryle Walker) ----------------//

View File

@ -1,6 +1,7 @@
// Copyright (C) 2002 Brad King (brad.king@kitware.com)
// Douglas Gregor (gregod@cs.rpi.edu)
// Peter Dimov
//
// Copyright (C) 2002, 2008 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@ -14,27 +15,31 @@
# include <boost/config.hpp>
# include <boost/detail/workaround.hpp>
namespace boost {
// Do not make addressof() inline. Breaks MSVC 7. (Peter Dimov)
// VC7 strips const from nested classes unless we add indirection here
# if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
template<class T> struct _addp
namespace boost
{
typedef T * type;
namespace detail
{
template<class T> struct addressof_impl
{
static inline T * f( T & v, long )
{
return reinterpret_cast<T*>(
&const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
}
static inline T * f( T * v, int )
{
return v;
}
};
template <typename T> typename _addp<T>::type
} // namespace detail
# else
template <typename T> T*
# endif
addressof(T& v)
template<class T> T * addressof( T & v )
{
return reinterpret_cast<T*>(
&const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
return boost::detail::addressof_impl<T>::f( v, 0 );
}
// Borland doesn't like casting an array reference to a char reference
@ -53,6 +58,6 @@ const T (*addressof(const T (&t)[N]))[N]
}
# endif
}
} // namespace boost
#endif // BOOST_UTILITY_ADDRESSOF_HPP

View File

@ -10,6 +10,46 @@
# error Boost result_of - do not include this file!
#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<
F, F(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
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3002)) && BOOST_PP_ITERATION() == 0
# define BOOST_RESULT_OF_ARGS void
@ -26,6 +66,8 @@ struct result_of<F(BOOST_RESULT_OF_ARGS)>
#undef BOOST_RESULT_OF_ARGS
#endif // defined(BOOST_HAS_DECLTYPE)
#if BOOST_PP_ITERATION() >= 1
namespace detail {

View File

@ -1,6 +1,6 @@
// Boost enable_if library
// Copyright 2003 <EFBFBD> The Trustees of Indiana University.
// Copyright 2003 (c) The Trustees of Indiana University.
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

View File

@ -10,13 +10,17 @@
#define BOOST_RESULT_OF_HPP
#include <boost/config.hpp>
#include <boost/type_traits/ice.hpp>
#include <boost/type.hpp>
#include <boost/preprocessor.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/if.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>
#ifndef BOOST_RESULT_OF_NUM_ARGS
# define BOOST_RESULT_OF_NUM_ARGS 10
@ -32,6 +36,7 @@ namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
template<typename F, typename FArgs, bool HasResultType> struct result_of_impl;
template<typename F> struct result_of_decltype_impl;
template<typename F>
struct result_of_void_impl

View File

@ -1,109 +1,102 @@
// (C) Copyright 2002-2007, Fernando Luis Cacciola Carballal.
// (C) Copyright 2002-2008, 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)
//
// 21 Ago 2002 (Created) Fernando Cacciola
// 07 Set 2007 (Worked around MSVC++ bug) Fernando Cacciola, Niels Dekker
// 16 Nov 2007 (Refactoring: removed private base classes) 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
//
#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
#include <boost/detail/select_type.hpp>
#include <boost/type_traits/cv_traits.hpp>
#include <boost/detail/workaround.hpp>
// Microsoft Visual C++ does not correctly support value initialization, as reported by
// Pavel Kuznetsov (MetaCommunications Engineering), 7/28/2005, Feedback ID 100744,
// Feedback Title: Value-initialization in new-expression
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
// The report was closed at 11/14/2006, and its status was set to "Closed (Won't Fix)".
// Luckily, even in the presence of this compiler bug, boost::value_initialized will still
// do its job correctly, when using the following workaround:
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
# define BOOST_UTILITY_VALUE_INIT_WORKAROUND
#endif
#ifdef BOOST_UTILITY_VALUE_INIT_WORKAROUND
// Note: The implementation of boost::value_initialized had to deal with the
// fact that various compilers haven't fully implemented value-initialization.
// The constructor of boost::value_initialized<T> works around these compiler
// issues, by clearing the bytes of T, before constructing the T object it
// contains. More details on these issues are at libs/utility/value_init.htm
#include <boost/aligned_storage.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/cv_traits.hpp>
#include <boost/type_traits/alignment_of.hpp>
#include <cstring>
#include <new>
#ifdef BOOST_MSVC
#pragma warning(push)
#if _MSC_VER >= 1310
// When using MSVC 7.1 or higher, placement new, "new (&x) T()", may trigger warning C4345:
// "behavior change: an object of POD type constructed with an initializer of the form ()
// will be default-initialized". There is no need to worry about this, though.
#pragma warning(disable: 4345)
#endif
#endif
namespace boost {
template<class T>
class value_initialized
{
private :
mutable typename ::boost::aligned_storage<sizeof(T), ::boost::alignment_of<T>::value>::type x;
struct wrapper
{
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
typename
#endif
remove_const<T>::type data;
};
mutable
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
typename
#endif
aligned_storage<sizeof(wrapper), alignment_of<wrapper>::value>::type x;
wrapper * wrapper_address() const
{
return static_cast<wrapper *>( static_cast<void*>(&x));
}
public :
value_initialized()
{
std::memset(&x, 0, sizeof(x));
new (&x) T();
#ifdef BOOST_MSVC
#pragma warning(push)
#if _MSC_VER >= 1310
// When using MSVC 7.1 or higher, the following placement new expression may trigger warning C4345:
// "behavior change: an object of POD type constructed with an initializer of the form ()
// will be default-initialized". It is safe to ignore this warning when using value_initialized.
#pragma warning(disable: 4345)
#endif
#endif
new (wrapper_address()) wrapper();
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
value_initialized(value_initialized const & arg)
{
new (wrapper_address()) wrapper( static_cast<wrapper const &>(*(arg.wrapper_address())));
}
value_initialized & operator=(value_initialized const & arg)
{
// Assignment is only allowed when T is non-const.
BOOST_STATIC_ASSERT( ! is_const<T>::value );
*wrapper_address() = static_cast<wrapper const &>(*(arg.wrapper_address()));
return *this;
}
~value_initialized()
{
void * ptr = &x;
static_cast<T*>(ptr)->T::~T();
wrapper_address()->wrapper::~wrapper();
}
T& data() const
{
void * ptr = &x;
return *static_cast<T*>(ptr);
return wrapper_address()->data;
}
operator T&() const { return this->data(); }
} ;
#ifdef BOOST_MSVC
// Restores the state of warning C4345.
#pragma warning(pop)
#endif
#else
namespace boost {
template<class T>
class value_initialized
{
public :
value_initialized() : x() {}
T& data() const { return x; }
operator T&() const { return this->data(); }
mutable
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
typename
#endif
::boost::remove_const<T>::type x ;
} ;
#endif
template<class T>
@ -117,6 +110,20 @@ T& get ( value_initialized<T>& x )
return x.data() ;
}
class initialized_value_t
{
public :
template <class T> operator T() const
{
return get( value_initialized<T>() );
}
};
initialized_value_t const initialized_value = {} ;
} // namespace boost

View File

@ -21,14 +21,15 @@
<a href="compressed_pair.htm">compressed_pair</a><br>
<a href="current_function.html">current_function</a><br>
<a href="enable_if.html">enable_if</a><br>
<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="operators.htm">operators</a><br>
<a href="throw_exception.html">throw_exception</a><br>
<a href="utility.htm">utility</a><br>
<a href="value_init.htm">value_init</a></p>
</blockquote>
<hr>
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
<p>© Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">
LICENSE_1_0.txt</a> or copy at

View File

@ -2029,13 +2029,13 @@ public:
<h2><a name="contributors">Contributors</a></h2>
<dl>
<dt><a href="../../people/dave_abrahams.htm">Dave Abrahams</a></dt>
<dt><a href="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a></dt>
<dd>Started the library and contributed the arithmetic operators in
<cite><a href=
"../../boost/operators.hpp">boost/operators.hpp</a></cite>.</dd>
<dt><a href="../../people/jeremy_siek.htm">Jeremy Siek</a></dt>
<dt><a href="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a></dt>
<dd>Contributed the <a href="#deref">dereference operators and iterator
helpers</a> in <cite><a href=
@ -2043,19 +2043,19 @@ public:
contributed <cite><a href=
"iterators_test.cpp">iterators_test.cpp</a></cite>.</dd>
<dt><a href="../../people/aleksey_gurtovoy.htm">Aleksey
<dt><a href="http://www.boost.org/people/aleksey_gurtovoy.htm">Aleksey
Gurtovoy</a></dt>
<dd>Contributed the code to support <a href="#chaining">base class
chaining</a> while remaining backward-compatible with old versions of
the library.</dd>
<dt><a href="../../people/beman_dawes.html">Beman Dawes</a></dt>
<dt><a href="http://www.boost.org/people/beman_dawes.html">Beman Dawes</a></dt>
<dd>Contributed <cite><a href=
"operators_test.cpp">operators_test.cpp</a></cite>.</dd>
<dt><a href="../../people/daryle_walker.html">Daryle Walker</a></dt>
<dt><a href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a></dt>
<dd>Contributed classes for the shift operators, equivalence, partial
ordering, and arithmetic conversions. Added the grouped operator

View File

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

View File

@ -315,7 +315,7 @@ Last modified: Mon Aug 11 11:27:03 EST 2003
<p><EFBFBD> Copyright 2003 The Trustees of Indiana University.
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)</p>
http://www.boost.org/LICENSE_1_0.txt)</p>
</body>

0
test/next_prior_test.cpp Executable file → Normal file
View File

View File

@ -11,35 +11,101 @@
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
struct int_result_type { typedef int result_type; };
struct int_result_type
{
typedef int result_type;
result_type operator()(float);
};
struct int_result_of
{
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
struct int_result_type_and_float_result_of_and_char_return
{
typedef int result_type;
template<typename F> struct result { typedef float type; };
char operator()(char);
};
template<typename T>
struct int_result_type_template { typedef int result_type; };
struct int_result_type_template
{
typedef int result_type;
result_type operator()(float);
};
template<typename T>
struct int_result_of_template
{
template<typename F> struct result;
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>
struct int_result_type_and_float_result_of_template
struct int_result_type_and_float_result_of_and_char_return_template
{
typedef int result_type;
template<typename F> struct result;
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 {};
@ -60,16 +126,37 @@ 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_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<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_of_template<void>(double)>::type, int>::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));
// 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<volatile int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_template<void>(char)>::type, int>::value));
#endif
// 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_ref(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr_0()>::type, int>::value));
@ -81,5 +168,27 @@ int main()
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<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));
#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;
}

View File

@ -68,7 +68,7 @@ const std::list&lt;T&gt;::iterator next = boost::next(prev, 2);</pre>
<p>The distance from the given iterator should be supplied as an absolute value. For
example, the iterator four iterators prior to the given iterator <code>p</code>
may be obtained by <code>prior(p, 4)</code>.</p>
<p>Contributed by <a href="../../people/dave_abrahams.htm">Dave Abrahams</a>. Two-argument versions by Daniel Walker.</p>
<p>Contributed by <a href="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>. Two-argument versions by Daniel Walker.</p>
<h2><a name="Class_noncopyable">Class noncopyable</a></h2>
<p>Class <strong>noncopyable</strong> is a base class.&nbsp; Derive your own class
from <strong>noncopyable</strong> when you want to prohibit copy construction
@ -89,7 +89,7 @@ const std::list&lt;T&gt;::iterator next = boost::next(prev, 2);</pre>
to verify class <b>noncopyable</b> works as expected. It has have been run
successfully under GCC 2.95, Metrowerks CodeWarrior 5.0, and Microsoft Visual
C++ 6.0 sp 3.</p>
<p>Contributed by <a href="../../people/dave_abrahams.htm">Dave Abrahams</a>.</p>
<p>Contributed by <a href="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>.</p>
<h3>Example</h3>
<blockquote>
<pre>// inside one of your own headers ...
@ -152,11 +152,13 @@ void f() {
...,t<em>N</em>)</code>. The implementation permits
the type <code>F</code> to be a function pointer,
function reference, member function pointer, or class
type. When <code>F</code> is a class type with a
member type <code>result_type</code>,
type.</p> <p>If your compiler does not support
<code>decltype</code>, then when <code>F</code> is a
class type with a member type <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is
<code>F::result_type</code>. Otherwise,
<code>F::result_type</code>. When <code>F</code>
does not contain <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is <code>F::result&lt;F(T1,
T2, ..., T<em>N</em>)&gt;::type</code> when

View File

@ -17,20 +17,23 @@
<dl>
<dt><a href="#rationale">Rationale</a></dt>
<dt><a href="#intro">Introduction</a></dt>
<dt><a href="#details">Details</a></dt>
</dl>
<ul>
<li><a href="#valueinit">value-initialization</a></li>
<li><a href="#valueinitsyn">value-initialization syntax</a></li>
<li><a href="#compiler_issues">compiler issues</a></li>
</ul>
<dl class="page-index">
<dt><a href="#types">Types</a></dt>
<dt><a href="#types">Types and objects</a></dt>
</dl>
<ul>
<li><a href="#val_init"><code>value_initialized&lt;&gt;</code></a></li>
<li><a href="#val_init"><code>template class value_initialized&lt;T&gt;</code></a></li>
<li><a href="#initialized_value"><code>initialized_value</code></a></li>
</ul>
<a href="#acknowledgements">Acknowledgements</a><br>
@ -44,24 +47,104 @@
for initialization. Depending on the type, the value of a newly constructed
object can be zero-initialized (logically 0), default-constructed (using
the default constructor), or indeterminate. When writing generic code,
this problem must be addressed. <code>value_initialized</code> provides
this problem must be addressed. The template <code>value_initialized</code> provides
a solution with consistent syntax for value initialization of scalar,
union and class types. <br>
union and class types.
Moreover, <code>value_initialized</code> offers a workaround to various
compiler issues regarding value-initialization.
Furthermore, a <code>const</code> object, <code>initialized_value</code> is provided,
to avoid repeating the type name when retrieving the value from a
<code>value_initialized&lt;T&gt;</code> object.
<br>
</p>
<h2><a name="intro"></a>Introduction</h2>
<p>The C++ standard [<a href="#references">1</a>] contains the definitions
<p>
There are various ways to initialize a variable, in C++. The following
declarations all <em>may</em> have a local variable initialized to its default
value:
<pre>
T1 var1;
T2 var2 = 0;
T3 var3 = {};
T4 var4 = T4();
</pre>
Unfortunately, whether or not any of those declarations correctly
initialize the variable very much depends on its type. The first
declaration is valid for any <a href="http://www.sgi.com/tech/stl/DefaultConstructible.html">
DefaultConstructible</a> type (by definition).
However, it does not always do an initialization!
It correctly initializes the variable when it's an instance of a
class, and the author of the class has provided a proper default
constructor. On the other hand, the value of <code>var1</code> is <em>indeterminate</em> when
its type is an arithmetic type, like <code>int</code>, <code>float</code>, or <code>char</code>.
An arithmetic variable
is of course initialized properly by the second declaration, <code>T2
var2 = 0</code>. But this initialization form usually won't work for a
class type (unless the class was especially written to support being
initialized that way). The third form, <code>T3 var3 = {}</code>
initializes an aggregate, typically a "C-style" <code>struct</code> or a "C-style" array.
However, the syntax is not allowed for a class that has an explicitly declared
constructor. (But watch out for an upcoming C++ language change,
by Bjarne Stroustrup et al [<a href="#references">1</a>]!)
The fourth form is the most generic form of them, as it
can be used to initialize arithmetic types, class types, aggregates, pointers, and
other types. The declaration, <code>T4 var4 = T4()</code>, should be read
as follows: First a temporary object is created, by <code>T4()</code>.
This object is <a href="#valueinit">value-initialized</a>. Next the temporary
object is copied to the named variable, <code>var4</code>. Afterwards, the temporary
is destroyed. While the copying and the destruction are likely to
be optimized away, C++ still requires the type <code>T4</code> to be
<a href="CopyConstructible.html">CopyConstructible</a>.
(So <code>T4</code> needs to be <em>both</em> DefaultConstructible <em>and</em> CopyConstructible.)
A class may not be CopyConstructible, for example because it may have a
private and undefined copy constructor,
or because it may be derived from <a href="utility.htm#Class_noncopyable">boost::noncopyable</a>.
Scott Meyers [<a href="#references">2</a>] explains why a class would be defined like that.
</p>
<p>
There is another, less obvious disadvantage to the fourth form, <code>T4 var4 = T4()</code>:
It suffers from various <a href="#compiler_issues">compiler issues</a>, causing
a variable to be left uninitialized in some compiler specific cases.
</p>
<p>
The template <a href="#val_init"><code>value_initialized</code></a>
offers a generic way to initialize
an object, like <code>T4 var4 = T4()</code>, but without requiring its type
to be CopyConstructible. And it offers a workaround to those compiler issues
regarding value-initialization as well! It allows getting an initialized
variable of any type; it <em>only</em> requires the type to be DefaultConstructible.
A properly <em>value-initialized</em> object of type <code>T</code> is
constructed by the following declaration:
<pre>
value_initialized&lt;T&gt; var;
</pre>
</p>
<p>
The <code>const</code> object <a href="#initialized_value"><code>initialized_value</code></a>
allows value-initializing a variable as follows:
<pre>
T var = initialized_value ;
</pre>
This form of initialization is semantically equivalent to <code>T4 var4 = T4()</code>,
but robust against the aforementioned compiler issues.
</p>
<h2><a name="details"></a>Details</h2>
<p>The C++ standard [<a href="#references">3</a>] contains the definitions
of <code>zero-initialization</code> and <code>default-initialization</code>.
Informally, zero-initialization means that the object is given the initial
value 0 (converted to the type) and default-initialization means that
POD [<a href="#references">2</a>] types are zero-initialized, while class
POD [<a href="#references">4</a>] types are zero-initialized, while non-POD class
types are initialized with their corresponding default constructors. A
<i>declaration</i> can contain an <i>initializer</i>, which specifies the
object's initial value. The initializer can be just '()', which states that
the object shall be default-initialized (but see below). However, if a <i>declaration</i>
the object shall be value-initialized (but see below). However, if a <i>declaration</i>
has no <i>initializer</i> and it is of a non-<code>const</code>, non-<code>static</code>
POD type, the initial value is indeterminate:<cite>(see &sect;8.5 for the
POD type, the initial value is indeterminate: <cite>(see &sect;8.5, [dcl.init], for the
accurate definitions).</cite></p>
<pre>int x ; // no initializer. x value is indeterminate.<br>std::string s ; // no initializer, s is default-constructed.<br><br>int y = int() ; <br>// y is initialized using copy-initialization<br>// but the temporary uses an empty set of parentheses as the initializer,<br>// so it is default-constructed.<br>// A default constructed POD type is zero-initialized,<br>// therefore, y == 0.<br><br>void foo ( std::string ) ;<br>foo ( std::string() ) ; <br>// the temporary string is default constructed <br>// as indicated by the initializer () </pre>
@ -87,14 +170,11 @@ the object shall be default-initialized (but see below). However, if a <i>decla
<p>In order to specify value-initialization of an object we need to use the
empty-set initializer: (). </p>
<p><i>(but recall that the current C++ Standard states that '()' invokes default-initialization,
not value-initialization)</i></p>
<p>As before, a declaration with no intializer specifies default-initialization,
and a declaration with a non-empty initializer specifies copy (=xxx) or
direct (xxx) initialization. </p>
<pre>template&lt;class T&gt; void eat(T);<br>int x ; // indeterminate initial value.<br>std::string s; // default-initialized.<br>eat ( int() ) ; // value-initialized<br>eat ( std::string() ) ; // value-initialied</pre>
<pre>template&lt;class T&gt; void eat(T);<br>int x ; // indeterminate initial value.<br>std::string s; // default-initialized.<br>eat ( int() ) ; // value-initialized<br>eat ( std::string() ) ; // value-initialized</pre>
<h4><a name="valueinitsyn">value-initialization</a> syntax</h4>
@ -102,7 +182,7 @@ not value-initialization)</i></p>
parentheses is not permitted by the syntax of initializers because it is
parsed as the declaration of a function taking no arguments: </p>
<pre>int x() ; // declares function int(*)()<br>int y ( int() ) ; // decalares function int(*)( int(*)() )</pre>
<pre>int x() ; // declares function int(*)()</pre>
<p>Thus, the empty () must be put in some other initialization context.</p>
@ -124,10 +204,52 @@ data member:</p>
<pre>template&lt;class T&gt; <br>struct W <br>{<br> // value-initialization of 'data' here.<br> W() : data() {}<br> T data ;<br>} ;<br>W&lt;int&gt; w ;<br>// w.data is value-initialized for any type. </pre>
<p><code>This is the solution supplied by the value_initialized&lt;&gt; template
class.</code></p>
<p>This is the solution as it was supplied by earlier versions of the
<code>value_initialized&lt;T&gt;</code> template
class. Unfortunately this approach suffered from various compiler issues.</p>
<h2><a name="types"></a>Types</h2>
<h4><a name="compiler_issues">compiler issues</a> </h4>
Various compilers haven't yet fully implemented value-initialization.
So when an object should be <em>value-initialized</em> (according to the C++ Standard),
it <em>may</em> in practice still be left uninitialized, because of those
compiler issues! It's hard to make a general statement on what those issues
are like, because they depend on the compiler you are using, its version number,
and the type of object you would like to have value-initialized.
Compilers usually support value-initialization for built-in types properly.
But objects of user-defined types that involve <em>aggregates</em> may <em>in some cases</em>
be partially, or even entirely left uninitialized, when they should be value-initialized.
</p>
<p>
We have encountered issues regarding value-initialization on compilers by
Microsoft, Sun, Borland, and GNU. Here is a list of bug reports on those issues:
<table summary="Compiler bug reports regarding value-initialization" border="0" cellpadding="7" cellspacing="1" >
<tr><td>
<a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744">
Microsoft Feedback ID 100744 - Value-initialization in new-expression</a>
<br>Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005-07-28
<br>
<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111">
GCC Bug 30111 - Value-initialization of POD base class doesn't initialize members</a>
<br>Reported by Jonathan Wakely, 2006-12-07
<br>
<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916">
GCC Bug 33916 - Default constructor fails to initialize array members</a>
<br>Reported by Michael Elizabeth Chastain, 2007-10-26
<br>
<a href="http://qc.codegear.com/wc/qcmain.aspx?d=51854">
Borland Report 51854 - Value-initialization: POD struct should be zero-initialized</a>
<br>Reported by Niels Dekker (LKEB, Leiden University Medical Center), 2007-09-11
<br>
</td></tr></table>
</p><p>
New versions of <code>value_initialized</code>
(Boost release version 1.35 or higher)
offer a workaround to these issues: <code>value_initialized</code> will now clear
its internal data, prior to constructing the object that it contains.
</p>
<h2><a name="types"></a>Types and objects</h2>
<h2><a name="val_init"><code>template class value_initialized&lt;T&gt;</code></a></h2>
@ -190,24 +312,76 @@ 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>
<h2><a name="initialized_value"><code>initialized_value</code></a></h2>
<pre>
namespace boost {
class initialized_value_t
{
public :
template &lt;class T&gt; operator T() const ;
};
initialized_value_t const initialized_value = {} ;
} // namespace boost
</pre>
<code>initialized_value</code> provides a convenient way to get
an initialized value: its conversion operator provides an appropriate
<em>value-initialized</em> object for any CopyConstructible type.
Suppose you need to have an initialized variable of type <code>T</code>.
You could do it as follows:
<pre>
T var = T();
</pre>
But as mentioned before, this form suffers from various compiler issues.
The template <code>value_initialized</code> offers a workaround:
<pre>
T var = get( value_initialized&lt;T&gt;() );
</pre>
Unfortunately both forms repeat the type name, which
is rather short now (<code>T</code>), but could of course be
more like <code>Namespace::Template&lt;Arg&gt;::Type</code>.
Instead, one could use <code>initialized_value</code> as follows:
<pre>
T var = initialized_value ;
</pre>
<h3><a name="references">References</a></h3>
[1] The C++ Standard, ISO/IEC 14882:98 <br>
[2] Plain Old Data
[1] Bjarne Stroustrup, Gabriel Dos Reis, and J. Stephen Adamczyk wrote
various papers, proposing to extend the support for brace-enclosed <em>initializer lists</em>
in the next version of C++.
This would allow a variable <code>var</code> of any DefaultConstructible type
<code>T</code> to be <em>value-initialized</em> by doing <code>T var = {}</code>.
The papers are listed at Bjarne's web page,
<a href="http://www.research.att.com/~bs/WG21.html">My C++ Standards committee papers</a> <br>
[2] Scott Meyers, Effective C++, Third Edition, item 6,
<em>Explicitly disallow the use of compiler-generated functions you do not want</em>,
<a href="http://www.aristeia.com/books.html">Scott Meyers: Books and CDs</a> <br>
[3] The C++ Standard, Second edition (2003), ISO/IEC 14882:2003 <br>
[4] POD stands for "Plain Old Data"
<h3><a name="acknowledgements"></a>Acknowledgements</h3>
value_initialized was developed by Fernando Cacciola, with help and
suggestions from David Abrahams and Darin Adler.<br>
Special thanks to Bj<EFBFBD>rn Karlsson who carefully edited and completed this documentation.
Special thanks to Bj&ouml;rn Karlsson who carefully edited and completed this documentation.
<p>value_initialized was reimplemented by Fernando Cacciola and Niels Dekker
for Boost release version 1.35 (2008), offering a workaround to various compiler issues.
</p>
<p>initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008).
</p>
<p>Developed by <a href="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</a>,
the latest version of this file can be found at <a
href="http://www.boost.org">www.boost.org</a>, and the boost discussion list
at <a href="http://www.yahoogroups.com/list/boost">www.yahoogroups.com/list/boost</a>.
href="http://www.boost.org">www.boost.org</a>.
</p>
<hr>
<p>Revised 19 September 2002</p>
<p>Revised 23 May 2008</p>
<p>&copy; Copyright Fernando Cacciola, 2002.</p>
<p>&copy; Copyright Fernando Cacciola, 2002, 2008.</p>
<p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>

View File

@ -1,4 +1,4 @@
// Copyright 2002, Fernando Luis Cacciola Carballal.
// Copyright 2002-2008, Fernando Luis Cacciola Carballal.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@ -6,12 +6,16 @@
//
// Test program for "boost/utility/value_init.hpp"
//
// Initial: 21 Agu 2002
// 21 Ago 2002 (Created) Fernando Cacciola
// 15 Jan 2008 (Added tests regarding compiler issues) Fernando Cacciola, Niels Dekker
// 23 May 2008 (Added tests regarding initialized_value) Niels Dekker
#include <cstring> // For memcmp.
#include <iostream>
#include <string>
#include "boost/utility/value_init.hpp"
#include <boost/shared_ptr.hpp>
#ifdef __BORLANDC__
#pragma hdrstop
@ -49,7 +53,7 @@ struct NonPODBase
struct NonPOD : NonPODBase
{
NonPOD () : id() {}
NonPOD ( std::string const& id_) : id(id_) {}
explicit NonPOD ( std::string const& id_) : id(id_) {}
friend std::ostream& operator << ( std::ostream& os, NonPOD const& npod )
{ return os << '(' << npod.id << ')' ; }
@ -152,6 +156,57 @@ struct AggregatePODStructWrapper
bool operator == ( AggregatePODStructWrapper const& lhs, AggregatePODStructWrapper const& rhs )
{ return lhs.dataMember == rhs.dataMember ; }
typedef unsigned char ArrayOfBytes[256];
//
// A struct that allows testing whether the appropriate copy functions are called.
//
struct CopyFunctionCallTester
{
bool is_copy_constructed;
bool is_assignment_called;
CopyFunctionCallTester()
: is_copy_constructed(false), is_assignment_called(false) {}
CopyFunctionCallTester(const CopyFunctionCallTester & )
: is_copy_constructed(true), is_assignment_called(false) {}
CopyFunctionCallTester & operator=(const CopyFunctionCallTester & )
{
is_assignment_called = true ;
return *this ;
}
};
template<class T>
void check_initialized_value ( T const& y )
{
T initializedValue = boost::initialized_value ;
BOOST_CHECK ( y == initializedValue ) ;
}
#ifdef __BORLANDC__
#if __BORLANDC__ == 0x582
void check_initialized_value( NonPOD const& )
{
// The initialized_value check is skipped for Borland 5.82
// and this type (NonPOD), because the following statement
// won't compile on this particular compiler version:
// NonPOD initializedValue = boost::initialized_value() ;
//
// 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
// Win32(R) and C++Builder(R) 2007 (http://dn.codegear.com/article/36575)
// say about similar statements:
// both of these statements now compile but under 5.82 got the error:
// Error E2015: Ambiguity between 'V::V(const A &)' and 'V::V(const V &)'
}
#endif
#endif
//
// 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.
@ -161,9 +216,13 @@ 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();
check_initialized_value(y);
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 ) ;
@ -175,6 +234,16 @@ bool test ( T const& y, T const& z )
x_c_ref = z ;
BOOST_CHECK ( x_c == z ) ;
boost::value_initialized<T> const copy1 = x;
BOOST_CHECK ( boost::get(copy1) == boost::get(x) ) ;
boost::value_initialized<T> copy2;
copy2 = x;
BOOST_CHECK ( boost::get(copy2) == boost::get(x) ) ;
boost::shared_ptr<boost::value_initialized<T> > ptr( new boost::value_initialized<T> );
BOOST_CHECK ( y == *ptr ) ;
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
boost::value_initialized<T const> cx ;
BOOST_CHECK ( y == cx ) ;
@ -184,6 +253,7 @@ bool test ( T const& y, T const& z )
BOOST_CHECK ( y == cx_c ) ;
BOOST_CHECK ( y == boost::get(cx_c) ) ;
#endif
return boost::minimal_test::errors_counter() == counter_before_test ;
}
@ -232,8 +302,30 @@ int test_main(int, char **)
aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct;
BOOST_CHECK ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) );
ArrayOfBytes zeroInitializedArrayOfBytes = { 0 };
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes;
BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0);
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes2;
valueInitializedArrayOfBytes2 = valueInitializedArrayOfBytes;
BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), get(valueInitializedArrayOfBytes2), sizeof(ArrayOfBytes)) == 0);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1;
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_copy_constructed);
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_assignment_called);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
BOOST_CHECK ( get(copyFunctionCallTester2).is_copy_constructed);
BOOST_CHECK ( ! get(copyFunctionCallTester2).is_assignment_called);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3;
copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed);
BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called);
return 0;
}
unsigned int expected_failures = 0;