forked from boostorg/utility
Compare commits
65 Commits
svn-branch
...
boost-1.41
Author | SHA1 | Date | |
---|---|---|---|
|
7ee1814664 | ||
|
583422cda2 | ||
|
ee146a02a1 | ||
|
c131cbd0b2 | ||
|
f8bef7ba95 | ||
|
e54cbf3053 | ||
|
d5291d08b8 | ||
|
61755605af | ||
|
cd12e322bd | ||
|
8cb975feb7 | ||
|
ffe151458e | ||
|
4003a9f74a | ||
|
211eb04f33 | ||
|
e57213b298 | ||
|
51f9adbfa1 | ||
|
eaaf17a88f | ||
|
48cfd42123 | ||
|
76aa5d2f27 | ||
|
ce67dde4f0 | ||
|
a69e872a91 | ||
|
e3640e45c2 | ||
|
b7cd171b2b | ||
|
b2e6a82adb | ||
|
390372294a | ||
|
ffbbf38e12 | ||
|
9e73b2c6ae | ||
|
633832e872 | ||
|
862cb2a4e0 | ||
|
b012f16ee5 | ||
|
3d96ab26d4 | ||
|
8652bf51ec | ||
|
9168cb9c61 | ||
|
e1991374ae | ||
|
d0ee9a7c28 | ||
|
10e83b490b | ||
|
4b24dba257 | ||
|
7a036f6f3a | ||
|
e632b0fb1f | ||
|
17bee9d43f | ||
|
492a8ad213 | ||
|
8827b8ed8b | ||
|
8849fbc52d | ||
|
50bc75a802 | ||
|
9b52e49fda | ||
|
ab479794f3 | ||
|
97b8966337 | ||
|
88099a882f | ||
|
d5554eb6d7 | ||
|
13bdfb8bbd | ||
|
74462349c2 | ||
|
6aa648d315 | ||
|
9ff18c2c96 | ||
|
d5ea07c737 | ||
|
aa0096bf42 | ||
|
005c2f3cc8 | ||
|
09f7aab52d | ||
|
30a40f9f76 | ||
|
d9f8bae673 | ||
|
3c7b409460 | ||
|
ee3551e8dc | ||
|
95da2e90de | ||
|
6dd93ab916 | ||
|
505d419a1b | ||
|
d968b5f5b9 | ||
|
d809d4e832 |
@@ -85,7 +85,7 @@
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
||||||
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
|
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
|
||||||
height="31" width="88"></a></p>
|
height="31" width="88"></a></p>
|
||||||
|
|
||||||
<p>Revised
|
<p>Revised
|
||||||
|
@@ -1,31 +0,0 @@
|
|||||||
#----------------------------------------------------------------------------
|
|
||||||
# This file was automatically generated from the original CMakeLists.txt file
|
|
||||||
# Add a variable to hold the headers for the library
|
|
||||||
set (lib_headers
|
|
||||||
assert.hpp
|
|
||||||
call_traits.hpp
|
|
||||||
checked_delete.hpp
|
|
||||||
compressed_pair.hpp
|
|
||||||
current_function.hpp
|
|
||||||
operators.hpp
|
|
||||||
throw_exception.hpp
|
|
||||||
utility.hpp
|
|
||||||
utility
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add a library target to the build system
|
|
||||||
boost_library_project(
|
|
||||||
utility
|
|
||||||
# SRCDIRS
|
|
||||||
TESTDIRS test
|
|
||||||
HEADERS ${lib_headers}
|
|
||||||
# DOCDIRS
|
|
||||||
DESCRIPTION "Various small utilities for C++ programming."
|
|
||||||
MODULARIZED
|
|
||||||
AUTHORS "David Abrahams <dave -at- boostpro.com>"
|
|
||||||
"Brad King"
|
|
||||||
"Douglas Gregor <doug.gregor -at- gmail.com>"
|
|
||||||
# MAINTAINERS
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
@@ -509,7 +509,7 @@ Returns the largest size that this Collection can ever have. <A href="#8">[8]</A
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
||||||
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
|
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
|
||||||
height="31" width="88"></a></p>
|
height="31" width="88"></a></p>
|
||||||
|
|
||||||
<p>Revised
|
<p>Revised
|
||||||
|
@@ -160,7 +160,7 @@ t.~T()
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
||||||
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
|
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
|
||||||
height="31" width="88"></a></p>
|
height="31" width="88"></a></p>
|
||||||
|
|
||||||
<p>Revised
|
<p>Revised
|
||||||
|
@@ -185,7 +185,7 @@
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
||||||
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
|
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
|
||||||
height="31" width="88"></a></p>
|
height="31" width="88"></a></p>
|
||||||
|
|
||||||
<p>Revised
|
<p>Revised
|
||||||
|
@@ -70,7 +70,7 @@
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
||||||
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
|
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
|
||||||
height="31" width="88"></a></p>
|
height="31" width="88"></a></p>
|
||||||
|
|
||||||
<p>Revised
|
<p>Revised
|
||||||
|
76
addressof_fn_test.cpp
Normal file
76
addressof_fn_test.cpp
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC)
|
||||||
|
#pragma warning(disable: 4786) // identifier truncated in debug info
|
||||||
|
#pragma warning(disable: 4710) // function not inlined
|
||||||
|
#pragma warning(disable: 4711) // function selected for automatic inline expansion
|
||||||
|
#pragma warning(disable: 4514) // unreferenced inline removed
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// addressof_fn_test.cpp: addressof( f )
|
||||||
|
//
|
||||||
|
// Copyright (c) 2008, 2009 Peter Dimov
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
|
#include <boost/utility/addressof.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
void f0()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f1(int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f2(int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f3(int, int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f4(int, int, int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f5(int, int, int, int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f6(int, int, int, int, int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f7(int, int, int, int, int, int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f8(int, int, int, int, int, int, int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void f9(int, int, int, int, int, int, int, int, int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_TEST( boost::addressof( f0 ) == &f0 );
|
||||||
|
BOOST_TEST( boost::addressof( f1 ) == &f1 );
|
||||||
|
BOOST_TEST( boost::addressof( f2 ) == &f2 );
|
||||||
|
BOOST_TEST( boost::addressof( f3 ) == &f3 );
|
||||||
|
BOOST_TEST( boost::addressof( f4 ) == &f4 );
|
||||||
|
BOOST_TEST( boost::addressof( f5 ) == &f5 );
|
||||||
|
BOOST_TEST( boost::addressof( f6 ) == &f6 );
|
||||||
|
BOOST_TEST( boost::addressof( f7 ) == &f7 );
|
||||||
|
BOOST_TEST( boost::addressof( f8 ) == &f8 );
|
||||||
|
BOOST_TEST( boost::addressof( f9 ) == &f9 );
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
95
addressof_test2.cpp
Normal file
95
addressof_test2.cpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
// Copyright (C) 2002 Brad King (brad.king@kitware.com)
|
||||||
|
// Douglas Gregor (gregod@cs.rpi.edu)
|
||||||
|
//
|
||||||
|
// Copyright 2009 Peter Dimov
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// For more information, see http://www.boost.org
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/utility/addressof.hpp>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(push, 3)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
|
template<class T> void scalar_test( T * = 0 )
|
||||||
|
{
|
||||||
|
T* px = new T();
|
||||||
|
|
||||||
|
T& x = *px;
|
||||||
|
BOOST_TEST( boost::addressof(x) == px );
|
||||||
|
|
||||||
|
const T& cx = *px;
|
||||||
|
const T* pcx = boost::addressof(cx);
|
||||||
|
BOOST_TEST( pcx == px );
|
||||||
|
|
||||||
|
volatile T& vx = *px;
|
||||||
|
volatile T* pvx = boost::addressof(vx);
|
||||||
|
BOOST_TEST( pvx == px );
|
||||||
|
|
||||||
|
const volatile T& cvx = *px;
|
||||||
|
const volatile T* pcvx = boost::addressof(cvx);
|
||||||
|
BOOST_TEST( pcvx == px );
|
||||||
|
|
||||||
|
delete px;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> void array_test( T * = 0 )
|
||||||
|
{
|
||||||
|
T nrg[3] = {1,2,3};
|
||||||
|
T (*pnrg)[3] = &nrg;
|
||||||
|
BOOST_TEST( boost::addressof(nrg) == pnrg );
|
||||||
|
|
||||||
|
T const cnrg[3] = {1,2,3};
|
||||||
|
T const (*pcnrg)[3] = &cnrg;
|
||||||
|
BOOST_TEST( boost::addressof(cnrg) == pcnrg );
|
||||||
|
}
|
||||||
|
|
||||||
|
class convertible {
|
||||||
|
public:
|
||||||
|
|
||||||
|
convertible( int = 0 )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class U> operator U () const
|
||||||
|
{
|
||||||
|
return U();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class convertible2 {
|
||||||
|
public:
|
||||||
|
|
||||||
|
convertible2( int = 0 )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
operator convertible2* () const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
scalar_test<convertible>();
|
||||||
|
scalar_test<convertible2>();
|
||||||
|
|
||||||
|
array_test<convertible>();
|
||||||
|
array_test<convertible2>();
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
@@ -146,7 +146,7 @@ int main()
|
|||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
||||||
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
|
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
|
||||||
height="31" width="88"></a></p>
|
height="31" width="88"></a></p>
|
||||||
|
|
||||||
<p>Revised
|
<p>Revised
|
||||||
|
@@ -99,7 +99,7 @@ directly to the container:</p>
|
|||||||
<H2><A NAME="framework"></A>Framework</H2>
|
<H2><A NAME="framework"></A>Framework</H2>
|
||||||
<p>
|
<p>
|
||||||
This library proposes a framework to allow some containers to directly contruct contained objects in-place without requiring
|
This library proposes a framework to allow some containers to directly contruct contained objects in-place without requiring
|
||||||
the entire set of constructor overloads ftom the contained type. It also allows the container to remove the CopyConstuctible
|
the entire set of constructor overloads from the contained type. It also allows the container to remove the CopyConstuctible
|
||||||
requirement from the contained type since objects can be directly constructed in-place without need of a copy.<br>
|
requirement from the contained type since objects can be directly constructed in-place without need of a copy.<br>
|
||||||
The only requirement on the container is that it must provide proper storage (that is, correctly aligned and sized).
|
The only requirement on the container is that it must provide proper storage (that is, correctly aligned and sized).
|
||||||
Naturally, the container will typically support uninitialized storage to avoid the in-place construction to override
|
Naturally, the container will typically support uninitialized storage to avoid the in-place construction to override
|
||||||
@@ -117,7 +117,7 @@ The following simplified example shows the basic idea. A complete example follow
|
|||||||
<pre>struct C
|
<pre>struct C
|
||||||
{
|
{
|
||||||
template<class InPlaceFactory>
|
template<class InPlaceFactory>
|
||||||
C ( InPlaceFactory const& aFactoty )
|
C ( InPlaceFactory const& aFactory )
|
||||||
:
|
:
|
||||||
contained_ ( uninitialized_storage() )
|
contained_ ( uninitialized_storage() )
|
||||||
{
|
{
|
||||||
|
@@ -6,12 +6,8 @@
|
|||||||
#ifndef UUID_1D94A7C6054E11DB9804B622A1EF5492
|
#ifndef UUID_1D94A7C6054E11DB9804B622A1EF5492
|
||||||
#define UUID_1D94A7C6054E11DB9804B622A1EF5492
|
#define UUID_1D94A7C6054E11DB9804B622A1EF5492
|
||||||
|
|
||||||
#include <boost/exception/diagnostic_information.hpp>
|
//The header <boost/exception.hpp> has been deprecated.
|
||||||
#include <boost/exception/error_info.hpp>
|
//Please #include <boost/exception/all.hpp> instead.
|
||||||
#include <boost/exception/exception.hpp>
|
#include <boost/exception/all.hpp>
|
||||||
#include <boost/exception/get_error_info.hpp>
|
|
||||||
#include <boost/exception/info.hpp>
|
|
||||||
#include <boost/exception/info_tuple.hpp>
|
|
||||||
#include <boost/exception_ptr.hpp>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -179,6 +179,11 @@ unwrap_ref(T& t)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T> inline T* get_pointer( reference_wrapper<T> const & r )
|
||||||
|
{
|
||||||
|
return r.get_pointer();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // #ifndef BOOST_REF_HPP_INCLUDED
|
#endif // #ifndef BOOST_REF_HPP_INCLUDED
|
||||||
|
12
include/boost/swap.hpp
Normal file
12
include/boost/swap.hpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Copyright (C) 2007 Joseph Gauterin
|
||||||
|
//
|
||||||
|
// 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 BOOST_SWAP_HPP
|
||||||
|
#define BOOST_SWAP_HPP
|
||||||
|
|
||||||
|
#include "boost/utility/swap.hpp"
|
||||||
|
|
||||||
|
#endif
|
@@ -21,6 +21,17 @@ namespace boost
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template<class T> struct addr_impl_ref
|
||||||
|
{
|
||||||
|
T & v_;
|
||||||
|
|
||||||
|
inline addr_impl_ref( T & v ): v_( v ) {}
|
||||||
|
inline operator T& () const { return v_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
addr_impl_ref & operator=(const addr_impl_ref &);
|
||||||
|
};
|
||||||
|
|
||||||
template<class T> struct addressof_impl
|
template<class T> struct addressof_impl
|
||||||
{
|
{
|
||||||
static inline T * f( T & v, long )
|
static inline T * f( T & v, long )
|
||||||
@@ -39,12 +50,40 @@ template<class T> struct addressof_impl
|
|||||||
|
|
||||||
template<class T> T * addressof( T & v )
|
template<class T> T * addressof( T & v )
|
||||||
{
|
{
|
||||||
|
#if defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) )
|
||||||
|
|
||||||
return boost::detail::addressof_impl<T>::f( v, 0 );
|
return boost::detail::addressof_impl<T>::f( v, 0 );
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
return boost::detail::addressof_impl<T>::f( boost::detail::addr_impl_ref<T>( v ), 0 );
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) )
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<class T> struct addressof_addp
|
||||||
|
{
|
||||||
|
typedef T * type;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template< class T, std::size_t N >
|
||||||
|
typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] )
|
||||||
|
{
|
||||||
|
return &t;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Borland doesn't like casting an array reference to a char reference
|
// Borland doesn't like casting an array reference to a char reference
|
||||||
// but these overloads work around the problem.
|
// but these overloads work around the problem.
|
||||||
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
#if defined( __BORLANDC__ ) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||||
template<typename T,std::size_t N>
|
template<typename T,std::size_t N>
|
||||||
T (*addressof(T (&t)[N]))[N]
|
T (*addressof(T (&t)[N]))[N]
|
||||||
{
|
{
|
||||||
@@ -56,7 +95,7 @@ const T (*addressof(const T (&t)[N]))[N]
|
|||||||
{
|
{
|
||||||
return reinterpret_cast<const T(*)[N]>(&t);
|
return reinterpret_cast<const T(*)[N]>(&t);
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
@@ -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 {
|
||||||
|
@@ -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>
|
||||||
{
|
{
|
||||||
@@ -81,8 +70,8 @@ struct result_of_nested_result : F::template result<FArgs>
|
|||||||
template<typename F, typename FArgs>
|
template<typename F, typename FArgs>
|
||||||
struct result_of_impl<F, FArgs, false>
|
struct result_of_impl<F, FArgs, false>
|
||||||
: mpl::if_<is_function_with_no_args<FArgs>,
|
: mpl::if_<is_function_with_no_args<FArgs>,
|
||||||
result_of_void_impl<F>,
|
result_of_void_impl<F>,
|
||||||
result_of_nested_result<F, FArgs> >::type
|
result_of_nested_result<F, FArgs> >::type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
} // end namespace detail
|
} // end namespace detail
|
||||||
|
55
include/boost/utility/swap.hpp
Normal file
55
include/boost/utility/swap.hpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
// Copyright (C) 2007, 2008 Steven Watanabe, Joseph Gauterin, Niels Dekker
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
// For more information, see http://www.boost.org
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BOOST_UTILITY_SWAP_HPP
|
||||||
|
#define BOOST_UTILITY_SWAP_HPP
|
||||||
|
|
||||||
|
// Note: the implementation of this utility contains various workarounds:
|
||||||
|
// - swap_impl is put outside the boost namespace, to avoid infinite
|
||||||
|
// recursion (causing stack overflow) when swapping objects of a primitive
|
||||||
|
// type.
|
||||||
|
// - swap_impl has a using-directive, rather than a using-declaration,
|
||||||
|
// because some compilers (including MSVC 7.1, Borland 5.9.3, and
|
||||||
|
// Intel 8.1) don't do argument-dependent lookup when it has a
|
||||||
|
// using-declaration instead.
|
||||||
|
// - boost::swap has two template arguments, instead of one, to
|
||||||
|
// avoid ambiguity when swapping objects of a Boost type that does
|
||||||
|
// not have its own boost::swap overload.
|
||||||
|
|
||||||
|
#include <algorithm> //for std::swap
|
||||||
|
#include <cstddef> //for std::size_t
|
||||||
|
|
||||||
|
namespace boost_swap_impl
|
||||||
|
{
|
||||||
|
template<class T>
|
||||||
|
void swap_impl(T& left, T& right)
|
||||||
|
{
|
||||||
|
using namespace std;//use std::swap if argument dependent lookup fails
|
||||||
|
swap(left,right);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, std::size_t N>
|
||||||
|
void swap_impl(T (& left)[N], T (& right)[N])
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
::boost_swap_impl::swap_impl(left[i], right[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template<class T1, class T2>
|
||||||
|
void swap(T1& left, T2& right)
|
||||||
|
{
|
||||||
|
::boost_swap_impl::swap_impl(left, right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@@ -8,6 +8,7 @@
|
|||||||
// 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
|
// 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola
|
||||||
|
// 20 Feb 2009 (Fixed logical const-ness issues) 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
|
||||||
@@ -90,7 +91,12 @@ class value_initialized
|
|||||||
wrapper_address()->wrapper::~wrapper();
|
wrapper_address()->wrapper::~wrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
T& data() const
|
T const & data() const
|
||||||
|
{
|
||||||
|
return wrapper_address()->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
T& data()
|
||||||
{
|
{
|
||||||
return wrapper_address()->data;
|
return wrapper_address()->data;
|
||||||
}
|
}
|
||||||
@@ -100,12 +106,16 @@ class value_initialized
|
|||||||
::boost::swap( this->data(), arg.data() );
|
::boost::swap( this->data(), arg.data() );
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T&() const { return this->data(); }
|
operator T const &() const { return this->data(); }
|
||||||
|
|
||||||
|
operator T&() { return this->data(); }
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T const& get ( value_initialized<T> const& x )
|
T const& get ( value_initialized<T> const& x )
|
||||||
{
|
{
|
||||||
|
@@ -1 +0,0 @@
|
|||||||
boost_module(utility DEPENDS iterator exception detail )
|
|
@@ -445,6 +445,9 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4);
|
|||||||
optional template parameter <code>B</code>, which is not shown, for the
|
optional template parameter <code>B</code>, which is not shown, for the
|
||||||
<a href="#chaining">base class chaining</a> technique.</p>
|
<a href="#chaining">base class chaining</a> technique.</p>
|
||||||
|
|
||||||
|
<p>The primary operand type <code>T</code> needs to be of class type,
|
||||||
|
built-in types are not supported.</p>
|
||||||
|
|
||||||
<table cellpadding="5" border="1" align="center">
|
<table cellpadding="5" border="1" align="center">
|
||||||
<caption>
|
<caption>
|
||||||
Simple Arithmetic Operator Template Classes
|
Simple Arithmetic Operator Template Classes
|
||||||
@@ -2130,7 +2133,7 @@ public:
|
|||||||
<p>Revised: 7 Aug 2008</p>
|
<p>Revised: 7 Aug 2008</p>
|
||||||
|
|
||||||
<p>Copyright © Beman Dawes, David Abrahams, 1999-2001.</p>
|
<p>Copyright © Beman Dawes, David Abrahams, 1999-2001.</p>
|
||||||
<p>Copyright © Daniel Frey, 2002-2008.</p>
|
<p>Copyright © Daniel Frey, 2002-2009.</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
|
||||||
|
43
ref_test.cpp
43
ref_test.cpp
@@ -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;
|
||||||
}
|
}
|
||||||
|
98
swap.html
Normal file
98
swap.html
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<title>Boost: Swap Documentation</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- Page header -->
|
||||||
|
<h2>
|
||||||
|
<img src="../../boost.png" alt="C++ Boost" align="middle" width="277" height="86"/>
|
||||||
|
Header <<a href="../../boost/swap.hpp">boost/swap.hpp</a>>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<h1>Swap</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<tt>template<class T> void swap(T& <em>left</em>, T& <em>right</em>);</tt>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Introduction -->
|
||||||
|
<p>
|
||||||
|
The template function <tt>boost::swap</tt> allows the values of two variables to be swapped, using argument dependent lookup to select a specialized swap function if available. If no specialized swap function is available, <tt>std::swap</tt> is used.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Rationale -->
|
||||||
|
<h2>Rationale</h2>
|
||||||
|
<p>
|
||||||
|
The generic <tt>std::swap</tt> function requires that the elements to be swapped are assignable and copy constructible. It is usually implemented using one copy construction and two assignments - this is often both unnecessarily restrictive and unnecessarily slow. In addition, where the generic swap implementation provides only the basic guarantee, specialized swap functions are often able to provide the no-throw exception guarantee (and it is considered best practice to do so where possible<sup><a href="#ref1">1</a></sup>).</p>
|
||||||
|
<p>
|
||||||
|
The alternative to using argument dependent lookup in this situation is to provide a template specialization of <tt>std::swap</tt> for every type that requires a specialized swap. Although this is legal C++, no Boost libraries use this method, whereas many Boost libraries provide specialized swap functions in their own namespaces.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<tt>boost::swap</tt> also supports swapping built-in arrays. Note that <tt>std::swap</tt> originally did not do so, but a request to add an overload of <tt>std::swap</tt> for built-in arrays has been accepted by the C++ Standards Committee<sup><a href="#ref2">2</a></sup>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Exception Safety -->
|
||||||
|
<h2>Exception Safety</h2>
|
||||||
|
<p>
|
||||||
|
<tt>boost::swap</tt> provides the same exception guarantee as the underlying swap function used, with one exception; for an array of type <tt>T[n]</tt>, where <tt>n > 1</tt> and the underlying swap function for <tt>T</tt> provides the strong exception guarantee, <tt>boost::swap</tt> provides only the basic exception guarantee.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Requirements -->
|
||||||
|
<h2>Requirements</h2>
|
||||||
|
<p>Either:</p>
|
||||||
|
<ul>
|
||||||
|
<li>T must be assignable</li>
|
||||||
|
<li>T must be copy constructible</li>
|
||||||
|
</ul>
|
||||||
|
<p>Or:</p>
|
||||||
|
<ul>
|
||||||
|
<li>A function with the signature <tt>swap(T&,T&)</tt> is available via argument dependent lookup</li>
|
||||||
|
</ul>
|
||||||
|
<p>Or:</p>
|
||||||
|
<ul>
|
||||||
|
<li>A template specialization of <tt>std::swap</tt> exists for T</li>
|
||||||
|
</ul>
|
||||||
|
<p>Or:</p>
|
||||||
|
<ul>
|
||||||
|
<li>T is a built-in array of swappable elements</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Portability -->
|
||||||
|
<h2>Portability</h2>
|
||||||
|
<p>
|
||||||
|
Several older compilers do not support argument dependent lookup ‒ on these compilers <tt>boost::swap</tt> will call <tt>std::swap</tt>, ignoring any specialized swap functions that could be found as a result of argument dependent lookup.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Credits -->
|
||||||
|
<h2>Credits</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<em>Niels Dekker</em> - for implementing and documenting support for built-in arrays
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<em><a href="mailto:Joseph.Gauterin@googlemail.com">Joseph Gauterin</a></em> - for the initial idea, implementation, tests, and documentation
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<em>Steven Watanabe</em> - for the idea to make <tt>boost::swap</tt> less specialized than <tt>std::swap</tt>, thereby allowing the function to have the name 'swap' without introducing ambiguity
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<!-- References -->
|
||||||
|
<hr/>
|
||||||
|
<p><sup><a id="ref1"/>[1]</sup>Scott Meyers, Effective C++ Third Edition, Item 25: "Consider support for a non-throwing swap"</p>
|
||||||
|
<p><sup><a id="ref2"/>[2]</sup><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#809">LWG Defect Report 809 (std::swap should be overloaded for array types)</a></p>
|
||||||
|
|
||||||
|
<!-- Copyright info -->
|
||||||
|
<hr/>
|
||||||
|
<p>Revised: 08 September 2009</p>
|
||||||
|
<p>
|
||||||
|
Copyright 2007 - 2009 Joseph Gauterin. Use, modification, and distribution are subject to the Boost Software License, Version 1.0.
|
||||||
|
(See accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -29,5 +29,9 @@ test-suite utility/swap
|
|||||||
[ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
[ run std_vector_of_global.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
[ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
[ run std_vector_of_other.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
[ run no_ambiguity_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
[ run no_ambiguity_in_boost.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
[ run swap_arrays.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
[ run array_of_array_of_class.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run array_of_array_of_int.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run array_of_class.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run array_of_int.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run array_of_template.cpp ../../../test/build//boost_test_exec_monitor/<link>static ]
|
||||||
;
|
;
|
||||||
|
69
swap/test/array_of_array_of_class.cpp
Normal file
69
swap/test/array_of_array_of_class.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// Tests swapping an array of arrays of swap_test_class objects by means of boost::swap.
|
||||||
|
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//Put test class in the global namespace
|
||||||
|
#include "./swap_test_class.hpp"
|
||||||
|
|
||||||
|
#include <algorithm> //for std::copy and std::equal
|
||||||
|
#include <cstddef> //for std::size_t
|
||||||
|
|
||||||
|
//Provide swap function in both the namespace of swap_test_class
|
||||||
|
//(which is the global namespace), and the std namespace.
|
||||||
|
//It's common to provide a swap function for a class in both
|
||||||
|
//namespaces. Scott Meyers recommends doing so: Effective C++,
|
||||||
|
//Third Edition, item 25, "Consider support for a non-throwing swap".
|
||||||
|
void swap(swap_test_class& left, swap_test_class& right)
|
||||||
|
{
|
||||||
|
left.swap(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
void swap(swap_test_class& left, swap_test_class& right)
|
||||||
|
{
|
||||||
|
left.swap(right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_main(int, char*[])
|
||||||
|
{
|
||||||
|
const std::size_t first_dimension = 3;
|
||||||
|
const std::size_t second_dimension = 4;
|
||||||
|
const std::size_t number_of_elements = first_dimension * second_dimension;
|
||||||
|
|
||||||
|
swap_test_class array1[first_dimension][second_dimension];
|
||||||
|
swap_test_class array2[first_dimension][second_dimension];
|
||||||
|
|
||||||
|
swap_test_class* const ptr1 = array1[0];
|
||||||
|
swap_test_class* const ptr2 = array2[0];
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < number_of_elements; ++i)
|
||||||
|
{
|
||||||
|
ptr1[i].set_data( static_cast<int>(i) );
|
||||||
|
ptr2[i].set_data( static_cast<int>(i + number_of_elements) );
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::swap(array1, array2);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < number_of_elements; ++i)
|
||||||
|
{
|
||||||
|
BOOST_CHECK_EQUAL(ptr1[i].get_data(), static_cast<int>(i + number_of_elements) );
|
||||||
|
BOOST_CHECK_EQUAL(ptr2[i].get_data(), static_cast<int>(i) );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(), number_of_elements);
|
||||||
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
42
swap/test/array_of_array_of_int.cpp
Normal file
42
swap/test/array_of_array_of_int.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// Tests swapping an array of arrays of integers by means of boost::swap.
|
||||||
|
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <algorithm> //for std::copy and std::equal
|
||||||
|
#include <cstddef> //for std::size_t
|
||||||
|
|
||||||
|
int test_main(int, char*[])
|
||||||
|
{
|
||||||
|
const std::size_t first_dimension = 3;
|
||||||
|
const std::size_t second_dimension = 4;
|
||||||
|
const std::size_t number_of_elements = first_dimension * second_dimension;
|
||||||
|
|
||||||
|
int array1[first_dimension][second_dimension];
|
||||||
|
int array2[first_dimension][second_dimension];
|
||||||
|
|
||||||
|
int* const ptr1 = array1[0];
|
||||||
|
int* const ptr2 = array2[0];
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < number_of_elements; ++i)
|
||||||
|
{
|
||||||
|
ptr1[i] = static_cast<int>(i);
|
||||||
|
ptr2[i] = static_cast<int>(i + number_of_elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::swap(array1, array2);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < number_of_elements; ++i)
|
||||||
|
{
|
||||||
|
BOOST_CHECK_EQUAL(ptr1[i], static_cast<int>(i + number_of_elements) );
|
||||||
|
BOOST_CHECK_EQUAL(ptr2[i], static_cast<int>(i) );
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -4,6 +4,8 @@
|
|||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// Tests swapping an array of arrays of swap_test_class objects by means of boost::swap.
|
||||||
|
|
||||||
#include <boost/utility/swap.hpp>
|
#include <boost/utility/swap.hpp>
|
||||||
#define BOOST_INCLUDE_MAIN
|
#define BOOST_INCLUDE_MAIN
|
||||||
#include <boost/test/test_tools.hpp>
|
#include <boost/test/test_tools.hpp>
|
||||||
@@ -11,6 +13,9 @@
|
|||||||
//Put test class in the global namespace
|
//Put test class in the global namespace
|
||||||
#include "./swap_test_class.hpp"
|
#include "./swap_test_class.hpp"
|
||||||
|
|
||||||
|
#include <algorithm> //for std::copy and std::equal
|
||||||
|
#include <cstddef> //for std::size_t
|
||||||
|
|
||||||
//Provide swap function in both the namespace of swap_test_class
|
//Provide swap function in both the namespace of swap_test_class
|
||||||
//(which is the global namespace), and the std namespace.
|
//(which is the global namespace), and the std namespace.
|
||||||
//It's common to provide a swap function for a class in both
|
//It's common to provide a swap function for a class in both
|
||||||
@@ -33,27 +38,24 @@ namespace std
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
const std::size_t dimension = 7;
|
const std::size_t array_size = 2;
|
||||||
|
const swap_test_class initial_array1[array_size] = { swap_test_class(1), swap_test_class(2) };
|
||||||
|
const swap_test_class initial_array2[array_size] = { swap_test_class(3), swap_test_class(4) };
|
||||||
|
|
||||||
swap_test_class array1[dimension];
|
swap_test_class array1[array_size];
|
||||||
swap_test_class array2[dimension];
|
swap_test_class array2[array_size];
|
||||||
boost::swap(array1, array2);
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(), dimension);
|
std::copy(initial_array1, initial_array1 + array_size, array1);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
|
std::copy(initial_array2, initial_array2 + array_size, array2);
|
||||||
|
|
||||||
swap_test_class::reset();
|
swap_test_class::reset();
|
||||||
|
boost::swap(array1, array2);
|
||||||
|
|
||||||
const std::size_t firstDimension = 3;
|
BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2));
|
||||||
const std::size_t secondDimension = 4;
|
BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1));
|
||||||
|
|
||||||
swap_test_class two_d_array1[firstDimension][secondDimension];
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(), array_size);
|
||||||
swap_test_class two_d_array2[firstDimension][secondDimension];
|
|
||||||
boost::swap(two_d_array1, two_d_array2);
|
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(), firstDimension*secondDimension);
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
35
swap/test/array_of_int.cpp
Normal file
35
swap/test/array_of_int.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// Tests swapping an array of integers by means of boost::swap.
|
||||||
|
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
#include <algorithm> //for std::copy and std::equal
|
||||||
|
#include <cstddef> //for std::size_t
|
||||||
|
|
||||||
|
|
||||||
|
int test_main(int, char*[])
|
||||||
|
{
|
||||||
|
const std::size_t array_size = 3;
|
||||||
|
const int initial_array1[array_size] = { 1, 2, 3 };
|
||||||
|
const int initial_array2[array_size] = { 4, 5, 6 };
|
||||||
|
|
||||||
|
int array1[array_size];
|
||||||
|
int array2[array_size];
|
||||||
|
|
||||||
|
std::copy(initial_array1, initial_array1 + array_size, array1);
|
||||||
|
std::copy(initial_array2, initial_array2 + array_size, array2);
|
||||||
|
|
||||||
|
boost::swap(array1, array2);
|
||||||
|
|
||||||
|
BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2));
|
||||||
|
BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
71
swap/test/array_of_template.cpp
Normal file
71
swap/test/array_of_template.cpp
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
// Tests swapping an array of swap_test_template<int> objects by means of boost::swap.
|
||||||
|
|
||||||
|
#include <boost/utility/swap.hpp>
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
//Put test class in the global namespace
|
||||||
|
#include "./swap_test_class.hpp"
|
||||||
|
|
||||||
|
#include <algorithm> //for std::copy and std::equal
|
||||||
|
#include <cstddef> //for std::size_t
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class swap_test_template
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef T template_argument;
|
||||||
|
swap_test_class swap_test_object;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline bool operator==(const swap_test_template<T> & lhs, const swap_test_template<T> & rhs)
|
||||||
|
{
|
||||||
|
return lhs.swap_test_object == rhs.swap_test_object;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
inline bool operator!=(const swap_test_template<T> & lhs, const swap_test_template<T> & rhs)
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Provide swap function in the namespace of swap_test_template
|
||||||
|
//(which is the global namespace). Note that it isn't allowed to put
|
||||||
|
//an overload of this function within the std namespace.
|
||||||
|
template <class T>
|
||||||
|
void swap(swap_test_template<T>& left, swap_test_template<T>& right)
|
||||||
|
{
|
||||||
|
left.swap_test_object.swap(right.swap_test_object);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_main(int, char*[])
|
||||||
|
{
|
||||||
|
const std::size_t array_size = 2;
|
||||||
|
const swap_test_template<int> initial_array1[array_size] = { swap_test_class(1), swap_test_class(2) };
|
||||||
|
const swap_test_template<int> initial_array2[array_size] = { swap_test_class(3), swap_test_class(4) };
|
||||||
|
|
||||||
|
swap_test_template<int> array1[array_size];
|
||||||
|
swap_test_template<int> array2[array_size];
|
||||||
|
|
||||||
|
std::copy(initial_array1, initial_array1 + array_size, array1);
|
||||||
|
std::copy(initial_array2, initial_array2 + array_size, array2);
|
||||||
|
|
||||||
|
swap_test_class::reset();
|
||||||
|
boost::swap(array1, array2);
|
||||||
|
|
||||||
|
BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2));
|
||||||
|
BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1));
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(), array_size);
|
||||||
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@@ -25,10 +25,17 @@ namespace boost
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
boost::swap_test_class object1;
|
const boost::swap_test_class initial_value1(1);
|
||||||
boost::swap_test_class object2;
|
const boost::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
boost::swap_test_class object1 = initial_value1;
|
||||||
|
boost::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
boost::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3);
|
||||||
|
|
||||||
|
@@ -25,10 +25,18 @@ namespace boost
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
boost::swap_test_class object1;
|
const boost::swap_test_class initial_value1(1);
|
||||||
boost::swap_test_class object2;
|
const boost::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
boost::swap_test_class object1 = initial_value1;
|
||||||
|
boost::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
boost::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -44,10 +44,18 @@ namespace other
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
other::swap_test_class object1;
|
const other::swap_test_class initial_value1(1);
|
||||||
other::swap_test_class object2;
|
const other::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
other::swap_test_class object1 = initial_value1;
|
||||||
|
other::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
other::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -19,10 +19,18 @@ void swap(swap_test_class& left, swap_test_class& right)
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
swap_test_class object1;
|
const swap_test_class initial_value1(1);
|
||||||
swap_test_class object2;
|
const swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
swap_test_class object1 = initial_value1;
|
||||||
|
swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -25,10 +25,18 @@ namespace other
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
other::swap_test_class object1;
|
const other::swap_test_class initial_value1(1);
|
||||||
other::swap_test_class object2;
|
const other::swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
other::swap_test_class object1 = initial_value1;
|
||||||
|
other::swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
other::swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -24,10 +24,18 @@ namespace std
|
|||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
{
|
{
|
||||||
swap_test_class object1;
|
const swap_test_class initial_value1(1);
|
||||||
swap_test_class object2;
|
const swap_test_class initial_value2(2);
|
||||||
|
|
||||||
|
swap_test_class object1 = initial_value1;
|
||||||
|
swap_test_class object2 = initial_value2;
|
||||||
|
|
||||||
|
swap_test_class::reset();
|
||||||
boost::swap(object1,object2);
|
boost::swap(object1,object2);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -36,8 +36,11 @@ int test_main(int, char*[])
|
|||||||
const vector_type::size_type initial_size1 = 1;
|
const vector_type::size_type initial_size1 = 1;
|
||||||
const vector_type::size_type initial_size2 = 2;
|
const vector_type::size_type initial_size2 = 2;
|
||||||
|
|
||||||
vector_type object1(initial_size1);
|
const vector_type initial_value1(initial_size1, swap_test_class_type(1));
|
||||||
vector_type object2(initial_size2);
|
const vector_type initial_value2(initial_size2, swap_test_class_type(2));
|
||||||
|
|
||||||
|
vector_type object1 = initial_value1;
|
||||||
|
vector_type object2 = initial_value2;
|
||||||
|
|
||||||
swap_test_class_type::reset();
|
swap_test_class_type::reset();
|
||||||
|
|
||||||
@@ -46,6 +49,9 @@ int test_main(int, char*[])
|
|||||||
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
||||||
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -29,8 +29,11 @@ int test_main(int, char*[])
|
|||||||
const vector_type::size_type initial_size1 = 1;
|
const vector_type::size_type initial_size1 = 1;
|
||||||
const vector_type::size_type initial_size2 = 2;
|
const vector_type::size_type initial_size2 = 2;
|
||||||
|
|
||||||
vector_type object1(initial_size1);
|
const vector_type initial_value1(initial_size1, swap_test_class(1));
|
||||||
vector_type object2(initial_size2);
|
const vector_type initial_value2(initial_size2, swap_test_class(2));
|
||||||
|
|
||||||
|
vector_type object1 = initial_value1;
|
||||||
|
vector_type object2 = initial_value2;
|
||||||
|
|
||||||
swap_test_class::reset();
|
swap_test_class::reset();
|
||||||
|
|
||||||
@@ -39,6 +42,9 @@ int test_main(int, char*[])
|
|||||||
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
||||||
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -36,8 +36,11 @@ int test_main(int, char*[])
|
|||||||
const vector_type::size_type initial_size1 = 1;
|
const vector_type::size_type initial_size1 = 1;
|
||||||
const vector_type::size_type initial_size2 = 2;
|
const vector_type::size_type initial_size2 = 2;
|
||||||
|
|
||||||
vector_type object1(initial_size1);
|
const vector_type initial_value1(initial_size1, swap_test_class_type(1));
|
||||||
vector_type object2(initial_size2);
|
const vector_type initial_value2(initial_size2, swap_test_class_type(2));
|
||||||
|
|
||||||
|
vector_type object1 = initial_value1;
|
||||||
|
vector_type object2 = initial_value2;
|
||||||
|
|
||||||
swap_test_class_type::reset();
|
swap_test_class_type::reset();
|
||||||
|
|
||||||
@@ -46,6 +49,9 @@ int test_main(int, char*[])
|
|||||||
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
BOOST_CHECK_EQUAL(object1.size(),initial_size2);
|
||||||
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
BOOST_CHECK_EQUAL(object2.size(),initial_size1);
|
||||||
|
|
||||||
|
BOOST_CHECK(object1 == initial_value2);
|
||||||
|
BOOST_CHECK(object2 == initial_value1);
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0);
|
||||||
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0);
|
||||||
|
|
||||||
|
@@ -12,8 +12,11 @@
|
|||||||
|
|
||||||
class swap_test_class
|
class swap_test_class
|
||||||
{
|
{
|
||||||
|
int m_data;
|
||||||
public:
|
public:
|
||||||
swap_test_class()
|
explicit swap_test_class(int arg = 0)
|
||||||
|
:
|
||||||
|
m_data(arg)
|
||||||
{
|
{
|
||||||
++constructCount();
|
++constructCount();
|
||||||
}
|
}
|
||||||
@@ -23,23 +26,39 @@ public:
|
|||||||
++destructCount();
|
++destructCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
swap_test_class(const swap_test_class&)
|
swap_test_class(const swap_test_class& arg)
|
||||||
|
:
|
||||||
|
m_data(arg.m_data)
|
||||||
{
|
{
|
||||||
++copyCount();
|
++copyCount();
|
||||||
++destructCount();
|
++destructCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
swap_test_class& operator=(const swap_test_class&)
|
swap_test_class& operator=(const swap_test_class& arg)
|
||||||
{
|
{
|
||||||
|
m_data = arg.m_data;
|
||||||
++copyCount();
|
++copyCount();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(swap_test_class& other)
|
void swap(swap_test_class& other)
|
||||||
{
|
{
|
||||||
|
const int temp = m_data;
|
||||||
|
m_data = other.m_data;
|
||||||
|
other.m_data = temp;
|
||||||
|
|
||||||
++swapCount();
|
++swapCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_data() const
|
||||||
|
{
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_data(int arg)
|
||||||
|
{
|
||||||
|
m_data = arg;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned int swap_count(){ return swapCount(); }
|
static unsigned int swap_count(){ return swapCount(); }
|
||||||
static unsigned int copy_count(){ return copyCount(); }
|
static unsigned int copy_count(){ return copyCount(); }
|
||||||
@@ -81,4 +100,15 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline bool operator==(const swap_test_class & lhs, const swap_test_class & rhs)
|
||||||
|
{
|
||||||
|
return lhs.get_data() == rhs.get_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator!=(const swap_test_class & lhs, const swap_test_class & rhs)
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,36 +0,0 @@
|
|||||||
boost_test_run(addressof_test ../addressof_test.cpp)
|
|
||||||
boost_test_run(assert_test ../assert_test.cpp)
|
|
||||||
boost_test_run(base_from_member_test ../base_from_member_test.cpp)
|
|
||||||
boost_test_run(binary_search_test ../binary_search_test.cpp)
|
|
||||||
boost_test_run(call_traits_test ../call_traits_test.cpp ARGS -u)
|
|
||||||
boost_test_compile_fail(checked_delete_test ../checked_delete_test.cpp)
|
|
||||||
boost_test_run(compressed_pair_test
|
|
||||||
../compressed_pair_test
|
|
||||||
DEPENDS boost_test_exec_monitor)
|
|
||||||
boost_test_run(current_function_test ../current_function_test.cpp)
|
|
||||||
boost_test_run(iterators_test
|
|
||||||
../iterators_test.cpp
|
|
||||||
DEPENDS boost_test_exec_monitor)
|
|
||||||
boost_test_run(next_prior_test DEPENDS boost_test_exec_monitor)
|
|
||||||
boost_test_compile_fail(noncopyable_test ../noncopyable_test.cpp)
|
|
||||||
boost_test_run(numeric_traits_test ../numeric_traits_test.cpp)
|
|
||||||
if (${CMAKE_SYSTEM} MATCHES "FreeBSD-.*")
|
|
||||||
boost_test_compile_fail("operators_test_compilerbug")
|
|
||||||
elseif(${CMAKE_SYSTEM} MATCHES "FreeBSD-.*")
|
|
||||||
boost_test_run(operators_test
|
|
||||||
../operators_test.cpp
|
|
||||||
DEPENDS boost_test_exec_monitor)
|
|
||||||
endif(${CMAKE_SYSTEM} MATCHES "FreeBSD-.*")
|
|
||||||
boost_test_compile(ref_ct_test ../ref_ct_test.cpp)
|
|
||||||
boost_test_run(ref_test
|
|
||||||
../ref_test.cpp
|
|
||||||
DEPENDS boost_test_exec_monitor)
|
|
||||||
boost_test_compile(result_of_test)
|
|
||||||
boost_test_run(shared_iterator_test ../shared_iterator_test.cpp)
|
|
||||||
boost_test_run(value_init_test ../value_init_test.cpp)
|
|
||||||
boost_test_compile_fail(value_init_test_fail1
|
|
||||||
../value_init_test_fail1.cpp)
|
|
||||||
boost_test_compile_fail(value_init_test_fail2
|
|
||||||
../value_init_test_fail2.cpp)
|
|
||||||
boost_test_compile_fail(value_init_test_fail3
|
|
||||||
../value_init_test_fail3.cpp)
|
|
@@ -11,7 +11,9 @@ import testing ;
|
|||||||
# Please keep the tests ordered by filename
|
# Please keep the tests ordered by filename
|
||||||
test-suite utility
|
test-suite utility
|
||||||
:
|
:
|
||||||
|
[ run ../addressof_fn_test.cpp ]
|
||||||
[ run ../addressof_test.cpp ]
|
[ run ../addressof_test.cpp ]
|
||||||
|
[ run ../addressof_test2.cpp ]
|
||||||
[ run ../assert_test.cpp ]
|
[ run ../assert_test.cpp ]
|
||||||
[ run ../base_from_member_test.cpp ]
|
[ run ../base_from_member_test.cpp ]
|
||||||
[ run ../binary_search_test.cpp ]
|
[ run ../binary_search_test.cpp ]
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -1,58 +1,15 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Boost: throw_exception.hpp documentation</title>
|
<meta http-equiv=refresh content="0; URL=../exception/doc/throw_exception.html">
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
<title>Automatic redirection</title>
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white" style="MARGIN-LEFT: 5%; MARGIN-RIGHT: 5%">
|
<body>
|
||||||
<table border="0" width="100%">
|
Automatic redirection failed, please go to
|
||||||
<tr>
|
<a href="../exception/doc/throw_exception.html">throw_exception.html</a>. <hr>
|
||||||
<td width="277"><A href="../../index.htm"> <img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86" border="0"></A>
|
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
||||||
</td>
|
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
<td align="center">
|
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||||
<h1>throw_exception.hpp</h1>
|
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||||
</td>
|
</body>
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan="2" height="64"> </td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
<p>
|
|
||||||
The header <STRONG><boost/throw_exception.hpp></STRONG> defines the
|
|
||||||
helper function <STRONG>boost::throw_exception</STRONG>. It is intended to be
|
|
||||||
used in Boost libraries that need to throw exceptions, but support
|
|
||||||
configurations and platforms where exceptions aren't available, as indicated by
|
|
||||||
the presence of the <STRONG>BOOST_NO_EXCEPTIONS</STRONG> <A href="../config/config.htm#macro_ref">
|
|
||||||
configuration macro</A>.
|
|
||||||
</p>
|
|
||||||
<P>When <STRONG>BOOST_NO_EXCEPTIONS</STRONG> is not defined, <tt>boost::throw_exception(e)</tt>
|
|
||||||
is equivalent to <tt>throw e</tt>. Otherwise, the function is left undefined,
|
|
||||||
and the user is expected to supply an appropriate definition. Callers of <tt>throw_exception</tt>
|
|
||||||
are allowed to assume that the function never returns; therefore, if the
|
|
||||||
user-defined <tt>throw_exception</tt> returns, the behavior is undefined.</P>
|
|
||||||
<h3><a name="Synopsis">Synopsis</a></h3>
|
|
||||||
<pre>
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef BOOST_NO_EXCEPTIONS
|
|
||||||
|
|
||||||
void throw_exception(std::exception const & e); // user defined
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
template<class E> void throw_exception(E const & e)
|
|
||||||
{
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
<p><br>
|
|
||||||
<small>Copyright <20> 2002 by Peter Dimov. 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 <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
@@ -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<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)></code> is
|
T<em>N</em>)></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<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)></code> is <code>F::result<F(T1,
|
T<em>N</em>)></code> is <code>F::result<F(T1,
|
||||||
T2, ..., T<em>N</em>)>::type</code> when
|
T2, ..., T<em>N</em>)>::type</code> when
|
||||||
|
@@ -253,7 +253,33 @@ its internal data, prior to constructing the object that it contains.
|
|||||||
|
|
||||||
<h2><a name="val_init"><code>template class value_initialized<T></code></a></h2>
|
<h2><a name="val_init"><code>template class value_initialized<T></code></a></h2>
|
||||||
|
|
||||||
<pre>namespace boost {<br><br>template<class T><br>class value_initialized<br>{<br> public :<br> value_initialized() : x() {}<br> operator T&() const { return x ; }<br> T& data() const { return x ; }<br> void swap( value_initialized<T>& );<br><br> private :<br> <i>unspecified</i> x ;<br>} ;<br><br>template<class T><br>T const& get ( value_initialized<T> const& x )<br>{<br> return x.data() ;<br>}<br><br>template<class T><br>T& get ( value_initialized<T>& x )<br>{<br> return x.data() ;<br>}<br><br>} // namespace boost<br></pre>
|
<pre>namespace boost {<br><br>template<class T><br>class value_initialized<br>{
|
||||||
|
<br> public :
|
||||||
|
<br> value_initialized() : x() {}
|
||||||
|
<br> operator T const &() const { return x ; }
|
||||||
|
<br> operator T&() { return x ; }
|
||||||
|
<br> T const &data() const { return x ; }
|
||||||
|
<br> T& data() { return x ; }
|
||||||
|
<br> void swap( value_initialized<T>& );
|
||||||
|
<br>
|
||||||
|
<br> private :
|
||||||
|
<br> <i>unspecified</i> x ;
|
||||||
|
<br>} ;
|
||||||
|
<br>
|
||||||
|
<br>template<class T>
|
||||||
|
<br>T const& get ( value_initialized<T> const& x )
|
||||||
|
<br>{
|
||||||
|
<br> return x.data() ;
|
||||||
|
<br>}
|
||||||
|
<br>
|
||||||
|
<br>template<class T>
|
||||||
|
<br>T& get ( value_initialized<T>& 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&'</code> whose wrapped object (data member of type <code>T</code>)
|
to <code>'T&'</code> whose wrapped object (data member of type <code>T</code>)
|
||||||
@@ -271,7 +297,8 @@ its internal data, prior to constructing the object that it contains.
|
|||||||
<code>T&</code>, the member function <code>data()</code>, or the
|
<code>T&</code>, the member function <code>data()</code>, or the
|
||||||
non-member function <code>get()</code>: </p>
|
non-member function <code>get()</code>: </p>
|
||||||
|
|
||||||
<pre>void watch(int);<br>value_initialized<int> x;<br><br>watch(x) ; // operator T& used.<br>watch(x.data());<br>watch( get(x) ) // function get() used</pre>
|
<pre>void watch(int);<br>value_initialized<int> x;
|
||||||
|
<br><br>watch(x) ; // operator T& used.<br>watch(x.data());<br>watch( get(x) ) // function get() used</pre>
|
||||||
|
|
||||||
<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
|
||||||
@@ -281,37 +308,34 @@ non-member function <code>get()</code>: </p>
|
|||||||
is swappable as well, by calling its <code>swap</code> member function
|
is swappable as well, by calling its <code>swap</code> member function
|
||||||
as well as by calling <code>boost::swap</code>.</p>
|
as well as by calling <code>boost::swap</code>.</p>
|
||||||
|
|
||||||
<pre>value_initialized<int> x ; <br>static_cast<int&>(x) = 1 ; // OK<br>get(x) = 1 ; // OK<br><br>value_initialized<int const> y ; <br>static_cast<int&>(y) = 1 ; // ERROR: cannot cast to int&<br>static_cast<int const&>(y) = 1 ; // ERROR: cannot modify a const value<br>get(y) = 1 ; // ERROR: cannot modify a const value</pre>
|
<pre>value_initialized<int> x ; <br>static_cast<int&>(x) = 1 ; // OK<br>get(x) = 1 ; // OK
|
||||||
|
<br><br>value_initialized<int const> y ; <br>static_cast<int&>(y) = 1 ; // ERROR: cannot cast to int&<br>static_cast<int const&>(y) = 1 ; // ERROR: cannot modify a const value<br>get(y) = 1 ; // ERROR: cannot modify a const value</pre>
|
||||||
|
|
||||||
<h3>Warning:</h3>
|
<h3>Warning:</h3>
|
||||||
|
|
||||||
<p>Both the conversion operator and the <code>data()</code> member function
|
<p>The <code>value_initialized</code> implementation of Boost version 1.40.0 and older
|
||||||
are <code>const</code> in order to allow access to the wrapped object
|
allowed <i>non-const</i> access to the wrapped object, from a constant wrapper,
|
||||||
from a constant wrapper:</p>
|
both by its conversion operator and its <code>data()</code> member function. For example:</p>
|
||||||
|
|
||||||
<pre>void foo(int);<br>value_initialized<int> const x ;<br>foo(x);<br></pre>
|
<pre>value_initialized<int> const x_c ;<br>int& xr = x_c ; // OK, conversion to int& available even though x_c is itself const.
|
||||||
|
<br>xr = 2 ; </pre>
|
||||||
|
|
||||||
<p>But notice that this conversion operator is to <code>T&</code> although
|
<p>The reason for this obscure behavior was that some compilers
|
||||||
it is itself <code>const</code>. As a consequence, if <code>T</code> is
|
didn't accept the following valid code:</p>
|
||||||
a non-<code>const</code> type, you can modify the wrapped object even from
|
|
||||||
within a constant wrapper:</p>
|
|
||||||
|
|
||||||
<pre>value_initialized<int> const x_c ;<br>int& xr = x_c ; // OK, conversion to int& available even though x_c is itself const.<br>xr = 2 ; </pre>
|
|
||||||
|
|
||||||
<p>The reason for this obscure behavior is that some commonly used compilers
|
|
||||||
just don't accept the following valid code:</p>
|
|
||||||
|
|
||||||
<pre>struct X<br>{<br> operator int&() ;<br> operator int const&() const ; <br>};<br>X x ;<br>(x == 1 ) ; // ERROR HERE!</pre>
|
<pre>struct X<br>{<br> operator int&() ;<br> operator int const&() const ; <br>};<br>X x ;<br>(x == 1 ) ; // ERROR HERE!</pre>
|
||||||
|
|
||||||
<p>These compilers complain about ambiguity between the conversion operators.
|
<p>The current version of <code>value_initialized</code> no longer has this obscure behavior.
|
||||||
This complaint is incorrect, but the only workaround that I know of is
|
As compilers nowadays widely support overloading the conversion operator by having a <code>const</code> and a <code>non-const</code> version, we have decided to fix the issue accordingly. So the current version supports the idea of logical constness.
|
||||||
to provide only one of them, which leads to the obscure behavior just explained.<br>
|
<br>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3>Recommended practice: The non-member get() idiom</h3>
|
<h3>Recommended practice: The non-member get() idiom</h3>
|
||||||
|
|
||||||
<p>The obscure behavior of being able to modify a non-<code>const</code>
|
<p>The obscure behavior of being able to modify a non-<code>const</code>
|
||||||
wrapped object from within a constant wrapper can be avoided if access to
|
wrapped object from within a constant wrapper (as was supported by previous
|
||||||
|
versions of <code>value_initialized</code>)
|
||||||
|
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<int> x ;<br>get(x) = 1 ; // OK<br><br>value_initialized<int const> cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int> const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int const> const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre>
|
<pre>value_initialized<int> x ;<br>get(x) = 1 ; // OK<br><br>value_initialized<int const> cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int> const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int const> const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre>
|
||||||
@@ -383,9 +407,9 @@ 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 03 October 2009</p>
|
||||||
|
|
||||||
<p>© Copyright Fernando Cacciola, 2002, 2008.</p>
|
<p>© Copyright Fernando Cacciola, 2002, 2009.</p>
|
||||||
|
|
||||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
<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>
|
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||||
|
@@ -260,7 +260,7 @@ bool test ( T const& y, T const& z )
|
|||||||
boost::value_initialized<T> const x_c ;
|
boost::value_initialized<T> const x_c ;
|
||||||
BOOST_CHECK ( y == x_c ) ;
|
BOOST_CHECK ( y == x_c ) ;
|
||||||
BOOST_CHECK ( y == boost::get(x_c) ) ;
|
BOOST_CHECK ( y == boost::get(x_c) ) ;
|
||||||
T& x_c_ref = x_c ;
|
T& x_c_ref = const_cast<T&>( boost::get(x_c) ) ;
|
||||||
x_c_ref = z ;
|
x_c_ref = z ;
|
||||||
BOOST_CHECK ( x_c == z ) ;
|
BOOST_CHECK ( x_c == z ) ;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user