forked from boostorg/utility
Compare commits
8 Commits
boost-1.48
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
|
6032348b4c | ||
|
3279399fe3 | ||
|
87875cadda | ||
|
c58748cfd9 | ||
|
58bb88d4bd | ||
|
11d50ecb9f | ||
|
636283d7c2 | ||
|
1df0bf80bc |
109
enable_if.html
109
enable_if.html
@@ -21,7 +21,6 @@
|
|||||||
<BR>
|
<BR>
|
||||||
<BR>
|
<BR>
|
||||||
Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.<BR>
|
Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.<BR>
|
||||||
Copyright 2011 Matt Calabrese.<BR>
|
|
||||||
<BR>
|
<BR>
|
||||||
<!--TOC section Introduction-->
|
<!--TOC section Introduction-->
|
||||||
|
|
||||||
@@ -82,7 +81,7 @@ definitions to find this out. Instantiating the latter definition with
|
|||||||
<PRE>int::result_type negate(const int&);
|
<PRE>int::result_type negate(const int&);
|
||||||
|
|
||||||
</PRE>
|
</PRE>
|
||||||
where the return type is invalid. If this were an error, adding an unrelated function template
|
where the return type is invalid. If this was an error, adding an unrelated function template
|
||||||
(that was never called) could break otherwise valid code.
|
(that was never called) could break otherwise valid code.
|
||||||
Due to the SFINAE principle the above example is not, however, erroneous.
|
Due to the SFINAE principle the above example is not, however, erroneous.
|
||||||
The latter definition of <TT>negate</TT> is simply removed from the overload resolution set.<BR>
|
The latter definition of <TT>negate</TT> is simply removed from the overload resolution set.<BR>
|
||||||
@@ -155,7 +154,6 @@ typename enable_if<boost::is_arithmetic<T>, T>::type
|
|||||||
foo(T t) { return t; }
|
foo(T t) { return t; }
|
||||||
|
|
||||||
</PRE>
|
</PRE>
|
||||||
|
|
||||||
<!--TOC section Using <TT>enable_if</TT>-->
|
<!--TOC section Using <TT>enable_if</TT>-->
|
||||||
|
|
||||||
<H2><A NAME="htoc5">3</A> Using <TT>enable_if</TT></H2><!--SEC END -->
|
<H2><A NAME="htoc5">3</A> Using <TT>enable_if</TT></H2><!--SEC END -->
|
||||||
@@ -164,19 +162,8 @@ foo(T t) { return t; }
|
|||||||
The <TT>enable_if</TT> templates are defined in
|
The <TT>enable_if</TT> templates are defined in
|
||||||
<TT>boost/utility/enable_if.hpp</TT>, which is included by <TT>boost/utility.hpp</TT>.<BR>
|
<TT>boost/utility/enable_if.hpp</TT>, which is included by <TT>boost/utility.hpp</TT>.<BR>
|
||||||
<BR>
|
<BR>
|
||||||
With respect to function templates, <TT>enable_if</TT> can be used in multiple different ways:
|
The <TT>enable_if</TT> template can be used either as the return type, or as an
|
||||||
|
extra argument. For example, the <TT>foo</TT> function in the previous section could also be written
|
||||||
<UL>
|
|
||||||
<LI>As the return type of an instantiatied function
|
|
||||||
<LI>As an extra parameter of an instantiated function
|
|
||||||
<LI>As an extra template parameter (useful only in a compiler that supports C++0x default
|
|
||||||
arguments for function template parameters, see <A href="#sec:enable_if_0x">Enabling function
|
|
||||||
templates in C++0x</a> for details)
|
|
||||||
</UL>
|
|
||||||
|
|
||||||
In the previous section, the return type form of <TT>enable_if</TT> was shown. As an example
|
|
||||||
of using the form of <TT>enable_if</TT> that works via an extra function parameter, the
|
|
||||||
<TT>foo</TT> function in the previous section could also be written
|
|
||||||
as:
|
as:
|
||||||
<PRE>template <class T>
|
<PRE>template <class T>
|
||||||
T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy = 0);
|
T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy = 0);
|
||||||
@@ -186,80 +173,18 @@ a default value to keep the parameter hidden from client code.
|
|||||||
Note that the second template argument was not given to <TT>enable_if</TT>, as the default
|
Note that the second template argument was not given to <TT>enable_if</TT>, as the default
|
||||||
<TT>void</TT> gives the desired behavior.<BR>
|
<TT>void</TT> gives the desired behavior.<BR>
|
||||||
<BR>
|
<BR>
|
||||||
Which way to write the enabler is largely a matter of taste, but for certain functions, only a
|
Whether to write the enabler as an argument or within the return type is
|
||||||
subset of the options is possible:
|
largely a matter of taste, but for certain functions, only one
|
||||||
|
alternative is possible:
|
||||||
<UL><LI>
|
<UL><LI>
|
||||||
Many operators have a fixed number of arguments, thus <TT>enable_if</TT> must be used either in the
|
Operators have a fixed number of arguments, thus <TT>enable_if</TT> must be used in the return type.
|
||||||
return type or in an extra template parameter.
|
<LI>Constructors and destructors do not have a return type; an extra argument is the only option.
|
||||||
<LI>Functions that have a variadic parameter list must use either the return type form or an extra
|
<LI>There does not seem to be a way to specify an enabler for a conversion operator. Converting constructors,
|
||||||
template parameter.
|
however, can have enablers as extra default arguments.
|
||||||
<LI>Constructors do not have a return type so you must use either an extra function parameter or an
|
|
||||||
extra template parameter.
|
|
||||||
<LI>Constructors that have a variadic parameter list must an extra template parameter.
|
|
||||||
<LI>Conversion operators can only be written with an extra template parameter.
|
|
||||||
</UL>
|
</UL>
|
||||||
<!--TOC subsection Enabling function templates in C++0x-->
|
|
||||||
|
|
||||||
<A NAME="sec:enable_if_0x"></A>
|
|
||||||
<H3><A NAME="htoc7">3.1</A> Enabling function templates in C++0x</H3><!--SEC END -->
|
|
||||||
|
|
||||||
In a compiler which supports C++0x default arguments for function template parameters, you can
|
|
||||||
enable and disable function templates by adding an additional template parameter. This approach
|
|
||||||
works in all situations where you would use either the return type form of <TT>enable_if</TT> or
|
|
||||||
the function parameter form, including operators, constructors, variadic function templates, and
|
|
||||||
even overloaded conversion operations.
|
|
||||||
|
|
||||||
As an example:
|
|
||||||
|
|
||||||
<PRE>#include <boost/type_traits/is_arithmetic.hpp>
|
|
||||||
#include <boost/type_traits/is_pointer.hpp>
|
|
||||||
#include <boost/utility/enable_if.hpp>
|
|
||||||
|
|
||||||
class test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// A constructor that works for any argument list of size 10
|
|
||||||
template< class... T
|
|
||||||
, typename boost::enable_if_c< sizeof...( T ) == 10, int >::type = 0
|
|
||||||
>
|
|
||||||
test( T&&... );
|
|
||||||
|
|
||||||
// A conversion operation that can convert to any arithmetic type
|
|
||||||
template< class T
|
|
||||||
, typename boost::enable_if< boost::is_arithmetic< T >, int >::type = 0
|
|
||||||
>
|
|
||||||
operator T() const;
|
|
||||||
|
|
||||||
// A conversion operation that can convert to any pointer type
|
|
||||||
template< class T
|
|
||||||
, typename boost::enable_if< boost::is_pointer< T >, int >::type = 0
|
|
||||||
>
|
|
||||||
operator T() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// Works
|
|
||||||
test test_( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
|
|
||||||
|
|
||||||
// Fails as expected
|
|
||||||
test fail_construction( 1, 2, 3, 4, 5 );
|
|
||||||
|
|
||||||
// Works by calling the conversion operator enabled for arithmetic types
|
|
||||||
int arithmetic_object = test_;
|
|
||||||
|
|
||||||
// Works by calling the conversion operator enabled for pointer types
|
|
||||||
int* pointer_object = test_;
|
|
||||||
|
|
||||||
// Fails as expected
|
|
||||||
struct {} fail_conversion = test_;
|
|
||||||
}
|
|
||||||
|
|
||||||
</PRE>
|
|
||||||
|
|
||||||
<!--TOC subsection Enabling template class specializations-->
|
<!--TOC subsection Enabling template class specializations-->
|
||||||
|
|
||||||
<H3><A NAME="htoc7">3.2</A> Enabling template class specializations</H3><!--SEC END -->
|
<H3><A NAME="htoc6">3.1</A> Enabling template class specializations</H3><!--SEC END -->
|
||||||
|
|
||||||
<A NAME="sec:enable_if_classes"></A>
|
<A NAME="sec:enable_if_classes"></A>
|
||||||
Class template specializations can be enabled or disabled with <TT>enable_if</TT>.
|
Class template specializations can be enabled or disabled with <TT>enable_if</TT>.
|
||||||
@@ -285,7 +210,7 @@ is the correct value.<BR>
|
|||||||
<BR>
|
<BR>
|
||||||
<!--TOC subsection Overlapping enabler conditions-->
|
<!--TOC subsection Overlapping enabler conditions-->
|
||||||
|
|
||||||
<H3><A NAME="htoc8">3.3</A> Overlapping enabler conditions</H3><!--SEC END -->
|
<H3><A NAME="htoc7">3.2</A> Overlapping enabler conditions</H3><!--SEC END -->
|
||||||
|
|
||||||
<A NAME="sec:overlapping_conditions"></A>
|
<A NAME="sec:overlapping_conditions"></A>
|
||||||
Once the compiler has examined the enabling conditions and included the
|
Once the compiler has examined the enabling conditions and included the
|
||||||
@@ -314,7 +239,7 @@ partial specializations as well.<BR>
|
|||||||
<BR>
|
<BR>
|
||||||
<!--TOC subsection Lazy <TT>enable_if</TT>-->
|
<!--TOC subsection Lazy <TT>enable_if</TT>-->
|
||||||
|
|
||||||
<H3><A NAME="htoc9">3.4</A> Lazy <TT>enable_if</TT></H3><!--SEC END -->
|
<H3><A NAME="htoc8">3.3</A> Lazy <TT>enable_if</TT></H3><!--SEC END -->
|
||||||
|
|
||||||
<A NAME="sec:enable_if_lazy"></A>
|
<A NAME="sec:enable_if_lazy"></A>
|
||||||
In some cases it is necessary to avoid instantiating part of a
|
In some cases it is necessary to avoid instantiating part of a
|
||||||
@@ -360,7 +285,7 @@ above example, <TT>is_multipliable<T, U>::value</TT> defines when
|
|||||||
<BR>
|
<BR>
|
||||||
<!--TOC subsection Compiler workarounds-->
|
<!--TOC subsection Compiler workarounds-->
|
||||||
|
|
||||||
<H3><A NAME="htoc10">3.5</A> Compiler workarounds</H3><!--SEC END -->
|
<H3><A NAME="htoc9">3.4</A> Compiler workarounds</H3><!--SEC END -->
|
||||||
|
|
||||||
<A NAME="sec:workarounds"></A>
|
<A NAME="sec:workarounds"></A>
|
||||||
Some compilers flag functions as ambiguous if the only distinguishing factor is a different
|
Some compilers flag functions as ambiguous if the only distinguishing factor is a different
|
||||||
@@ -442,9 +367,9 @@ David Vandevoorde and Nicolai M. Josuttis.
|
|||||||
Addison-Wesley, 2002.</DL>
|
Addison-Wesley, 2002.</DL>
|
||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<p>Copyright Jaakko Järvi<sup>*</sup>, Jeremiah Willcock<sup>*</sup>, Andrew Lumsdaine<sup>*</sup>, Matt Calabrese<BR>
|
<p>Copyright Jaakko Järvi, Jeremiah Willcock and Andrew Lumsdaine<BR>
|
||||||
<EM>{jajarvi|jewillco|lums}@osl.iu.edu, rivorus@gmail.com</EM><BR>
|
<EM>{jajarvi|jewillco|lums}@osl.iu.edu</EM><BR>
|
||||||
<sup>*</sup>Indiana University<BR>
|
Indiana University<BR>
|
||||||
Open Systems Lab<br/>
|
Open Systems Lab<br/>
|
||||||
Use, modification and distribution are subject to the
|
Use, modification and distribution are subject to the
|
||||||
Boost Software License, Version 1.0.
|
Boost Software License, Version 1.0.
|
||||||
|
@@ -28,7 +28,7 @@ namespace detail
|
|||||||
inline void current_function_helper()
|
inline void current_function_helper()
|
||||||
{
|
{
|
||||||
|
|
||||||
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__)
|
#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600))
|
||||||
|
|
||||||
# define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__
|
# define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__
|
||||||
|
|
||||||
@@ -65,4 +65,3 @@ inline void current_function_helper()
|
|||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED
|
#endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED
|
||||||
|
|
||||||
|
@@ -35,10 +35,7 @@ struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)>
|
|||||||
|
|
||||||
#if !defined(BOOST_NO_DECLTYPE) && defined(BOOST_RESULT_OF_USE_DECLTYPE)
|
#if !defined(BOOST_NO_DECLTYPE) && defined(BOOST_RESULT_OF_USE_DECLTYPE)
|
||||||
|
|
||||||
// As of N2588, C++0x result_of only supports function call
|
// Uses declval following N3225 20.7.7.6 when F is not a pointer.
|
||||||
// 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())
|
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_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
|
struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
|
||||||
@@ -56,18 +53,15 @@ struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
|
|||||||
|
|
||||||
namespace detail {
|
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())
|
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)>
|
||||||
class cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
|
struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
|
||||||
{
|
{
|
||||||
static F f;
|
typedef decltype(
|
||||||
BOOST_PP_REPEAT(BOOST_PP_ITERATION(), BOOST_RESULT_OF_STATIC_MEMBERS, _)
|
boost::declval<F>()(
|
||||||
public:
|
BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), declval<T, >() BOOST_PP_INTERCEPT)
|
||||||
typedef decltype(f(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),t))) type;
|
)
|
||||||
|
) type;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@@ -13,7 +13,9 @@
|
|||||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||||
#include <boost/preprocessor/punctuation/comma_if.hpp>
|
#include <boost/preprocessor/punctuation/comma_if.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
|
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
|
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
|
||||||
|
#include <boost/preprocessor/facilities/intercept.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>
|
||||||
@@ -22,6 +24,7 @@
|
|||||||
#include <boost/type_traits/is_pointer.hpp>
|
#include <boost/type_traits/is_pointer.hpp>
|
||||||
#include <boost/type_traits/is_member_function_pointer.hpp>
|
#include <boost/type_traits/is_member_function_pointer.hpp>
|
||||||
#include <boost/type_traits/remove_cv.hpp>
|
#include <boost/type_traits/remove_cv.hpp>
|
||||||
|
#include <boost/utility/declval.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
|
||||||
|
10
index.html
10
index.html
@@ -14,21 +14,28 @@
|
|||||||
<p>But that doesn't mean there isn't useful stuff here. Take a look:</p>
|
<p>But that doesn't mean there isn't useful stuff here. Take a look:</p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
|
<a href="utility.htm#addressof">addressof</a><br>
|
||||||
<a href="assert.html">assert</a><br>
|
<a href="assert.html">assert</a><br>
|
||||||
<a href="base_from_member.html">base_from_member</a><br>
|
<a href="base_from_member.html">base_from_member</a><br>
|
||||||
|
<a href="utility.htm#BOOST_BINARY">BOOST_BINARY</a><br>
|
||||||
<a href="call_traits.htm">call_traits</a><br>
|
<a href="call_traits.htm">call_traits</a><br>
|
||||||
<a href="checked_delete.html">checked_delete</a><br>
|
<a href="checked_delete.html">checked_delete</a><br>
|
||||||
<a href="compressed_pair.htm">compressed_pair</a><br>
|
<a href="compressed_pair.htm">compressed_pair</a><br>
|
||||||
<a href="current_function.html">current_function</a><br>
|
<a href="current_function.html">current_function</a><br>
|
||||||
<a href="doc/html/declval.html">declval</a><br>
|
<a href="doc/html/declval.html">declval</a><br>
|
||||||
<a href="enable_if.html">enable_if</a><br>
|
<a href="enable_if.html">enable_if</a><br>
|
||||||
|
<a href="in_place_factories.html">in_place_factory</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="generator_iterator.htm">generator iterator adaptors</a><br>
|
||||||
|
<a href="utility.htm#functions_next_prior">next/prior</a><br>
|
||||||
|
<a href="utility.htm#Class_noncopyable">noncopyable</a><br>
|
||||||
<a href="operators.htm">operators</a><br>
|
<a href="operators.htm">operators</a><br>
|
||||||
|
<a href="utility.htm#result_of">result_of</a><br>
|
||||||
<a href="swap.html">swap</a><br>
|
<a href="swap.html">swap</a><br>
|
||||||
<a href="throw_exception.html">throw_exception</a><br>
|
<a href="throw_exception.html">throw_exception</a><br>
|
||||||
<a href="utility.htm">utility</a><br>
|
<a href="utility.htm">utility</a><br>
|
||||||
<a href="value_init.htm">value_init</a></p>
|
<a href="value_init.htm">value_init</a>
|
||||||
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<hr>
|
<hr>
|
||||||
<p>© Copyright Beman Dawes, 2001</p>
|
<p>© Copyright Beman Dawes, 2001</p>
|
||||||
@@ -41,4 +48,3 @@
|
|||||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->07 November, 2006<!--webbot bot="Timestamp" endspan i-checksum="39368" --></p>
|
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->07 November, 2006<!--webbot bot="Timestamp" endspan i-checksum="39368" --></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
@@ -98,6 +98,11 @@ struct no_result_type_or_result_of
|
|||||||
unsigned int operator()();
|
unsigned int operator()();
|
||||||
unsigned short operator()() volatile;
|
unsigned short operator()() volatile;
|
||||||
const unsigned short operator()() const volatile;
|
const unsigned short operator()() const volatile;
|
||||||
|
#if !defined(BOOST_NO_RVALUE_REFERENCES)
|
||||||
|
short operator()(int&&);
|
||||||
|
int operator()(int&);
|
||||||
|
long operator()(int const&);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -108,6 +113,11 @@ struct no_result_type_or_result_of_template
|
|||||||
unsigned int operator()();
|
unsigned int operator()();
|
||||||
unsigned short operator()() volatile;
|
unsigned short operator()() volatile;
|
||||||
const unsigned short operator()() const volatile;
|
const unsigned short operator()() const volatile;
|
||||||
|
#if !defined(BOOST_NO_RVALUE_REFERENCES)
|
||||||
|
short operator()(int&&);
|
||||||
|
int operator()(int&);
|
||||||
|
long operator()(int const&);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct X {};
|
struct X {};
|
||||||
@@ -232,6 +242,14 @@ int main()
|
|||||||
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<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<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));
|
BOOST_STATIC_ASSERT((is_same<result_of<const volatile no_result_type_or_result_of_template<void>(void)>::type, const unsigned short>::value));
|
||||||
|
#if !defined(BOOST_NO_RVALUE_REFERENCES)
|
||||||
|
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(int&&)>::type, short>::value));
|
||||||
|
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(int&)>::type, int>::value));
|
||||||
|
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(int const&)>::type, long>::value));
|
||||||
|
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(int&&)>::type, short>::value));
|
||||||
|
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(int&)>::type, int>::value));
|
||||||
|
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(int const&)>::type, long>::value));
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "boost/test/minimal.hpp"
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sample POD type
|
// Sample POD type
|
||||||
@@ -215,7 +215,7 @@ template<class T>
|
|||||||
void check_initialized_value ( T const& y )
|
void check_initialized_value ( T const& y )
|
||||||
{
|
{
|
||||||
T initializedValue = boost::initialized_value ;
|
T initializedValue = boost::initialized_value ;
|
||||||
BOOST_CHECK ( y == initializedValue ) ;
|
BOOST_TEST ( y == initializedValue ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
@@ -245,128 +245,125 @@ void check_initialized_value( NonPOD const& )
|
|||||||
template<class T>
|
template<class T>
|
||||||
bool test ( T const& y, T const& z )
|
bool test ( T const& y, T const& z )
|
||||||
{
|
{
|
||||||
const boost::unit_test::counter_t counter_before_test = boost::minimal_test::errors_counter();
|
const int errors_before_test = boost::detail::test_errors();
|
||||||
|
|
||||||
check_initialized_value(y);
|
check_initialized_value(y);
|
||||||
|
|
||||||
boost::value_initialized<T> x ;
|
boost::value_initialized<T> x ;
|
||||||
BOOST_CHECK ( y == x ) ;
|
BOOST_TEST ( y == x ) ;
|
||||||
BOOST_CHECK ( y == boost::get(x) ) ;
|
BOOST_TEST ( y == boost::get(x) ) ;
|
||||||
|
|
||||||
static_cast<T&>(x) = z ;
|
static_cast<T&>(x) = z ;
|
||||||
boost::get(x) = z ;
|
boost::get(x) = z ;
|
||||||
BOOST_CHECK ( x == z ) ;
|
BOOST_TEST ( x == z ) ;
|
||||||
|
|
||||||
boost::value_initialized<T> const x_c ;
|
boost::value_initialized<T> const x_c ;
|
||||||
BOOST_CHECK ( y == x_c ) ;
|
BOOST_TEST ( y == x_c ) ;
|
||||||
BOOST_CHECK ( y == boost::get(x_c) ) ;
|
BOOST_TEST ( y == boost::get(x_c) ) ;
|
||||||
T& x_c_ref = const_cast<T&>( boost::get(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_TEST ( x_c == z ) ;
|
||||||
|
|
||||||
boost::value_initialized<T> const copy1 = x;
|
boost::value_initialized<T> const copy1 = x;
|
||||||
BOOST_CHECK ( boost::get(copy1) == boost::get(x) ) ;
|
BOOST_TEST ( boost::get(copy1) == boost::get(x) ) ;
|
||||||
|
|
||||||
boost::value_initialized<T> copy2;
|
boost::value_initialized<T> copy2;
|
||||||
copy2 = x;
|
copy2 = x;
|
||||||
BOOST_CHECK ( boost::get(copy2) == boost::get(x) ) ;
|
BOOST_TEST ( boost::get(copy2) == boost::get(x) ) ;
|
||||||
|
|
||||||
boost::shared_ptr<boost::value_initialized<T> > ptr( new boost::value_initialized<T> );
|
boost::shared_ptr<boost::value_initialized<T> > ptr( new boost::value_initialized<T> );
|
||||||
BOOST_CHECK ( y == *ptr ) ;
|
BOOST_TEST ( y == *ptr ) ;
|
||||||
|
|
||||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||||
boost::value_initialized<T const> cx ;
|
boost::value_initialized<T const> cx ;
|
||||||
BOOST_CHECK ( y == cx ) ;
|
BOOST_TEST ( y == cx ) ;
|
||||||
BOOST_CHECK ( y == boost::get(cx) ) ;
|
BOOST_TEST ( y == boost::get(cx) ) ;
|
||||||
|
|
||||||
boost::value_initialized<T const> const cx_c ;
|
boost::value_initialized<T const> const cx_c ;
|
||||||
BOOST_CHECK ( y == cx_c ) ;
|
BOOST_TEST ( y == cx_c ) ;
|
||||||
BOOST_CHECK ( y == boost::get(cx_c) ) ;
|
BOOST_TEST ( y == boost::get(cx_c) ) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return boost::minimal_test::errors_counter() == counter_before_test ;
|
return boost::detail::test_errors() == errors_before_test ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_main(int, char **)
|
int main(int, char **)
|
||||||
{
|
{
|
||||||
BOOST_CHECK ( test( 0,1234 ) ) ;
|
BOOST_TEST ( test( 0,1234 ) ) ;
|
||||||
BOOST_CHECK ( test( 0.0,12.34 ) ) ;
|
BOOST_TEST ( test( 0.0,12.34 ) ) ;
|
||||||
BOOST_CHECK ( test( POD(0,0,0.0), POD('a',1234,56.78f) ) ) ;
|
BOOST_TEST ( test( POD(0,0,0.0), POD('a',1234,56.78f) ) ) ;
|
||||||
BOOST_CHECK ( test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ) ;
|
BOOST_TEST ( test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ) ;
|
||||||
|
|
||||||
NonPOD NonPOD_object( std::string("NonPOD_object") );
|
NonPOD NonPOD_object( std::string("NonPOD_object") );
|
||||||
BOOST_CHECK ( test<NonPOD *>( 0, &NonPOD_object ) ) ;
|
BOOST_TEST ( test<NonPOD *>( 0, &NonPOD_object ) ) ;
|
||||||
|
|
||||||
AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 };
|
AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 };
|
||||||
AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 };
|
AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 };
|
||||||
BOOST_CHECK ( test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct) );
|
BOOST_TEST ( test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct) );
|
||||||
|
|
||||||
StringAndInt stringAndInt0;
|
StringAndInt stringAndInt0;
|
||||||
StringAndInt stringAndInt1;
|
StringAndInt stringAndInt1;
|
||||||
stringAndInt0.i = 0;
|
stringAndInt0.i = 0;
|
||||||
stringAndInt1.i = 1;
|
stringAndInt1.i = 1;
|
||||||
stringAndInt1.s = std::string("1");
|
stringAndInt1.s = std::string("1");
|
||||||
BOOST_CHECK ( test(stringAndInt0, stringAndInt1) );
|
BOOST_TEST ( test(stringAndInt0, stringAndInt1) );
|
||||||
|
|
||||||
StructWithDestructor structWithDestructor0;
|
StructWithDestructor structWithDestructor0;
|
||||||
StructWithDestructor structWithDestructor1;
|
StructWithDestructor structWithDestructor1;
|
||||||
structWithDestructor0.i = 0;
|
structWithDestructor0.i = 0;
|
||||||
structWithDestructor1.i = 1;
|
structWithDestructor1.i = 1;
|
||||||
BOOST_CHECK ( test(structWithDestructor0, structWithDestructor1) );
|
BOOST_TEST ( test(structWithDestructor0, structWithDestructor1) );
|
||||||
|
|
||||||
StructWithVirtualFunction structWithVirtualFunction0;
|
StructWithVirtualFunction structWithVirtualFunction0;
|
||||||
StructWithVirtualFunction structWithVirtualFunction1;
|
StructWithVirtualFunction structWithVirtualFunction1;
|
||||||
structWithVirtualFunction0.i = 0;
|
structWithVirtualFunction0.i = 0;
|
||||||
structWithVirtualFunction1.i = 1;
|
structWithVirtualFunction1.i = 1;
|
||||||
BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) );
|
BOOST_TEST ( test(structWithVirtualFunction0, structWithVirtualFunction1) );
|
||||||
|
|
||||||
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct0;
|
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct0;
|
||||||
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct1;
|
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct1;
|
||||||
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct0) = zeroInitializedAggregatePODStruct;
|
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct0) = zeroInitializedAggregatePODStruct;
|
||||||
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct1) = nonZeroInitializedAggregatePODStruct;
|
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct1) = nonZeroInitializedAggregatePODStruct;
|
||||||
BOOST_CHECK ( test(derivedFromAggregatePODStruct0, derivedFromAggregatePODStruct1) );
|
BOOST_TEST ( test(derivedFromAggregatePODStruct0, derivedFromAggregatePODStruct1) );
|
||||||
|
|
||||||
AggregatePODStructWrapper aggregatePODStructWrapper0;
|
AggregatePODStructWrapper aggregatePODStructWrapper0;
|
||||||
AggregatePODStructWrapper aggregatePODStructWrapper1;
|
AggregatePODStructWrapper aggregatePODStructWrapper1;
|
||||||
aggregatePODStructWrapper0.dataMember = zeroInitializedAggregatePODStruct;
|
aggregatePODStructWrapper0.dataMember = zeroInitializedAggregatePODStruct;
|
||||||
aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct;
|
aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct;
|
||||||
BOOST_CHECK ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) );
|
BOOST_TEST ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) );
|
||||||
|
|
||||||
ArrayOfBytes zeroInitializedArrayOfBytes = { 0 };
|
ArrayOfBytes zeroInitializedArrayOfBytes = { 0 };
|
||||||
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes;
|
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes;
|
||||||
BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0);
|
BOOST_TEST (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0);
|
||||||
|
|
||||||
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes2;
|
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes2;
|
||||||
valueInitializedArrayOfBytes2 = valueInitializedArrayOfBytes;
|
valueInitializedArrayOfBytes2 = valueInitializedArrayOfBytes;
|
||||||
BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), get(valueInitializedArrayOfBytes2), sizeof(ArrayOfBytes)) == 0);
|
BOOST_TEST (std::memcmp(get(valueInitializedArrayOfBytes), get(valueInitializedArrayOfBytes2), sizeof(ArrayOfBytes)) == 0);
|
||||||
|
|
||||||
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1;
|
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1;
|
||||||
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_copy_constructed);
|
BOOST_TEST ( ! get(copyFunctionCallTester1).is_copy_constructed);
|
||||||
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_assignment_called);
|
BOOST_TEST ( ! get(copyFunctionCallTester1).is_assignment_called);
|
||||||
|
|
||||||
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
|
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
|
||||||
BOOST_CHECK ( get(copyFunctionCallTester2).is_copy_constructed);
|
BOOST_TEST ( get(copyFunctionCallTester2).is_copy_constructed);
|
||||||
BOOST_CHECK ( ! get(copyFunctionCallTester2).is_assignment_called);
|
BOOST_TEST ( ! get(copyFunctionCallTester2).is_assignment_called);
|
||||||
|
|
||||||
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3;
|
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3;
|
||||||
copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
|
copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
|
||||||
BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed);
|
BOOST_TEST ( ! get(copyFunctionCallTester3).is_copy_constructed);
|
||||||
BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called);
|
BOOST_TEST ( get(copyFunctionCallTester3).is_assignment_called);
|
||||||
|
|
||||||
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester1;
|
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester1;
|
||||||
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester2;
|
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester2;
|
||||||
get(swapFunctionCallTester1).data = 1;
|
get(swapFunctionCallTester1).data = 1;
|
||||||
get(swapFunctionCallTester2).data = 2;
|
get(swapFunctionCallTester2).data = 2;
|
||||||
boost::swap(swapFunctionCallTester1, swapFunctionCallTester2);
|
boost::swap(swapFunctionCallTester1, swapFunctionCallTester2);
|
||||||
BOOST_CHECK( get(swapFunctionCallTester1).data == 2 );
|
BOOST_TEST( get(swapFunctionCallTester1).data == 2 );
|
||||||
BOOST_CHECK( get(swapFunctionCallTester2).data == 1 );
|
BOOST_TEST( get(swapFunctionCallTester2).data == 1 );
|
||||||
BOOST_CHECK( get(swapFunctionCallTester1).is_custom_swap_called );
|
BOOST_TEST( get(swapFunctionCallTester1).is_custom_swap_called );
|
||||||
BOOST_CHECK( get(swapFunctionCallTester2).is_custom_swap_called );
|
BOOST_TEST( get(swapFunctionCallTester2).is_custom_swap_called );
|
||||||
|
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int expected_failures = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user