mirror of
https://github.com/boostorg/function.git
synced 2026-01-31 08:12:11 +00:00
Compare commits
1 Commits
boost-1.60
...
sandbox-br
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
029639b6ac |
@@ -3,7 +3,7 @@
|
|||||||
# Distributed under the Boost Software License, Version 1.0.
|
# Distributed under the Boost Software License, Version 1.0.
|
||||||
# (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)
|
||||||
project function/doc ;
|
project boost/doc ;
|
||||||
import boostbook : boostbook ;
|
import boostbook : boostbook ;
|
||||||
|
|
||||||
boostbook function-doc
|
boostbook function-doc
|
||||||
|
|||||||
@@ -13,15 +13,6 @@
|
|||||||
|
|
||||||
<itemizedlist spacing="compact">
|
<itemizedlist spacing="compact">
|
||||||
|
|
||||||
<listitem><para><bold>Version 1.52.0</bold>: </para>
|
|
||||||
<itemizedlist spacing="compact">
|
|
||||||
<listitem><para>Move constructors and move assignment
|
|
||||||
operators added (only for compilers with C++11 rvalue
|
|
||||||
references support). Original patch
|
|
||||||
contributed by Antony Polukhin.</para></listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</listitem>
|
|
||||||
|
|
||||||
<listitem><para><bold>Version 1.37.0</bold>: </para>
|
<listitem><para><bold>Version 1.37.0</bold>: </para>
|
||||||
<itemizedlist spacing="compact">
|
<itemizedlist spacing="compact">
|
||||||
<listitem><para>Improved the performance of Boost.Function's
|
<listitem><para>Improved the performance of Boost.Function's
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
<para>A function object <code>f</code> of
|
<para>A function object <code>f</code> of
|
||||||
type <code>F</code> is
|
type <code>F</code> is
|
||||||
<emphasis>stateless</emphasis> if it is a function pointer or if
|
<emphasis>stateless</emphasis> if it is a function pointer or if
|
||||||
<code><classname>boost::is_stateless</classname><F></code>
|
<code><classname>boost::is_stateless</classname><T></code>
|
||||||
is true. The construction of or copy to a Boost.Function object
|
is true. The construction of or copy to a Boost.Function object
|
||||||
from a stateless function object will not cause exceptions to be
|
from a stateless function object will not cause exceptions to be
|
||||||
thrown and will not allocate any storage.
|
thrown and will not allocate any storage.
|
||||||
@@ -203,15 +203,6 @@
|
|||||||
<throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
|
<throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
|
||||||
</constructor>
|
</constructor>
|
||||||
|
|
||||||
<constructor>
|
|
||||||
<parameter name="f">
|
|
||||||
<paramtype><classname>functionN</classname>&&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<requires><simpara>C++11 compatible compiler.</simpara></requires>
|
|
||||||
<postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
|
|
||||||
<throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
|
|
||||||
</constructor>
|
|
||||||
|
|
||||||
<constructor>
|
<constructor>
|
||||||
<template>
|
<template>
|
||||||
<template-type-parameter name="F"/>
|
<template-type-parameter name="F"/>
|
||||||
@@ -245,15 +236,6 @@
|
|||||||
</parameter>
|
</parameter>
|
||||||
<postconditions><simpara>If copy construction does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. If copy construction does throw, <code>this-><methodname>empty</methodname>()</code>.</simpara></postconditions>
|
<postconditions><simpara>If copy construction does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. If copy construction does throw, <code>this-><methodname>empty</methodname>()</code>.</simpara></postconditions>
|
||||||
</copy-assignment>
|
</copy-assignment>
|
||||||
|
|
||||||
<copy-assignment>
|
|
||||||
<parameter name="f">
|
|
||||||
<paramtype><classname>functionN</classname>&&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<requires><simpara>C++11 compatible compiler.</simpara></requires>
|
|
||||||
<postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
|
|
||||||
<throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
|
|
||||||
</copy-assignment>
|
|
||||||
|
|
||||||
<method-group name="modifiers">
|
<method-group name="modifiers">
|
||||||
<method name="swap">
|
<method name="swap">
|
||||||
@@ -625,16 +607,7 @@
|
|||||||
<postconditions><simpara>Contains a copy of the <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>.</simpara></postconditions>
|
<postconditions><simpara>Contains a copy of the <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>.</simpara></postconditions>
|
||||||
<throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
|
<throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
|
||||||
</constructor>
|
</constructor>
|
||||||
|
|
||||||
<constructor>
|
|
||||||
<parameter name="f">
|
|
||||||
<paramtype><classname>functionN</classname>&&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<requires><simpara>C++11 compatible compiler.</simpara></requires>
|
|
||||||
<postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
|
|
||||||
<throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
|
|
||||||
</constructor>
|
|
||||||
|
|
||||||
<constructor>
|
<constructor>
|
||||||
<parameter name="f">
|
<parameter name="f">
|
||||||
<paramtype>const <classname>function</classname>&</paramtype>
|
<paramtype>const <classname>function</classname>&</paramtype>
|
||||||
@@ -643,15 +616,6 @@
|
|||||||
<throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
|
<throws><simpara>Will not throw unless copying the target of <code>f</code> throws.</simpara></throws>
|
||||||
</constructor>
|
</constructor>
|
||||||
|
|
||||||
<constructor>
|
|
||||||
<parameter name="f">
|
|
||||||
<paramtype><classname>function</classname>&&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<requires><simpara>C++11 compatible compiler.</simpara></requires>
|
|
||||||
<postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
|
|
||||||
<throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
|
|
||||||
</constructor>
|
|
||||||
|
|
||||||
<constructor>
|
<constructor>
|
||||||
<template>
|
<template>
|
||||||
<template-type-parameter name="F"/>
|
<template-type-parameter name="F"/>
|
||||||
@@ -681,19 +645,10 @@
|
|||||||
|
|
||||||
<copy-assignment>
|
<copy-assignment>
|
||||||
<parameter name="f">
|
<parameter name="f">
|
||||||
<paramtype>const <classname>functionN</classname>&</paramtype>
|
<paramtype>const <classname>function</classname>&</paramtype>
|
||||||
</parameter>
|
</parameter>
|
||||||
<postconditions><simpara>If copy construction does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. If copy construction does throw, <code>this-><methodname>empty</methodname>()</code>.</simpara></postconditions>
|
<postconditions><simpara>If copy construction does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. If copy construction does throw, <code>this-><methodname>empty</methodname>()</code>.</simpara></postconditions>
|
||||||
</copy-assignment>
|
</copy-assignment>
|
||||||
|
|
||||||
<copy-assignment>
|
|
||||||
<parameter name="f">
|
|
||||||
<paramtype><classname>functionN</classname>&&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<requires><simpara>C++11 compatible compiler.</simpara></requires>
|
|
||||||
<postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
|
|
||||||
<throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
|
|
||||||
</copy-assignment>
|
|
||||||
|
|
||||||
<copy-assignment>
|
<copy-assignment>
|
||||||
<parameter name="f">
|
<parameter name="f">
|
||||||
@@ -702,15 +657,6 @@
|
|||||||
<postconditions><simpara>If copy construction of the target of <code>f</code> does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. </simpara></postconditions>
|
<postconditions><simpara>If copy construction of the target of <code>f</code> does not throw, <code>*this</code> targets a copy of <code>f</code>'s target, if it has one, or is empty if <code>f.<methodname>empty</methodname>()</code>. </simpara></postconditions>
|
||||||
<throws><simpara>Will not throw when the target of <code>f</code> is a stateless function object or a reference to the function object. If copy construction does throw, <code>this-><methodname>empty</methodname>()</code>.</simpara></throws>
|
<throws><simpara>Will not throw when the target of <code>f</code> is a stateless function object or a reference to the function object. If copy construction does throw, <code>this-><methodname>empty</methodname>()</code>.</simpara></throws>
|
||||||
</copy-assignment>
|
</copy-assignment>
|
||||||
|
|
||||||
<copy-assignment>
|
|
||||||
<parameter name="f">
|
|
||||||
<paramtype><classname>function</classname>&&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<requires><simpara>C++11 compatible compiler.</simpara></requires>
|
|
||||||
<postconditions><simpara>Moves the value from <code>f</code> to <code>*this</code>. If the argument has its function object allocated on the heap, its buffer will be assigned to <code>*this</code> leaving argument empty.</simpara></postconditions>
|
|
||||||
<throws><simpara>Will not throw unless argument has its function object allocated not on the heap and copying the target of <code>f</code> throws.</simpara></throws>
|
|
||||||
</copy-assignment>
|
|
||||||
|
|
||||||
<method-group name="modifiers">
|
<method-group name="modifiers">
|
||||||
<method name="swap">
|
<method name="swap">
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <boost/type_traits/is_integral.hpp>
|
#include <boost/type_traits/is_integral.hpp>
|
||||||
#include <boost/type_traits/is_volatile.hpp>
|
#include <boost/type_traits/is_volatile.hpp>
|
||||||
#include <boost/type_traits/composite_traits.hpp>
|
#include <boost/type_traits/composite_traits.hpp>
|
||||||
|
#include <boost/type_traits/ice.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/mpl/if.hpp>
|
#include <boost/mpl/if.hpp>
|
||||||
#include <boost/detail/workaround.hpp>
|
#include <boost/detail/workaround.hpp>
|
||||||
@@ -55,7 +56,7 @@
|
|||||||
// need to use std::type_info::name to compare instead of operator==.
|
// need to use std::type_info::name to compare instead of operator==.
|
||||||
#if defined( BOOST_NO_TYPEID )
|
#if defined( BOOST_NO_TYPEID )
|
||||||
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
||||||
#elif defined(__GNUC__) \
|
#elif (defined(__GNUC__) && __GNUC__ >= 3) \
|
||||||
|| defined(_AIX) \
|
|| defined(_AIX) \
|
||||||
|| ( defined(__sgi) && defined(__host_mips))
|
|| ( defined(__sgi) && defined(__host_mips))
|
||||||
# include <cstring>
|
# include <cstring>
|
||||||
@@ -65,16 +66,25 @@
|
|||||||
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__ICL) && __ICL <= 600 || defined(__MWERKS__) && __MWERKS__ < 0x2406 && !defined(BOOST_STRICT_CONFIG)
|
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__ICL) && __ICL <= 600 || defined(__MWERKS__) && __MWERKS__ < 0x2406 && !defined(BOOST_STRICT_CONFIG)
|
||||||
# define BOOST_FUNCTION_TARGET_FIX(x) x
|
# define BOOST_FUNCTION_TARGET_FIX(x) x
|
||||||
#else
|
#else
|
||||||
# define BOOST_FUNCTION_TARGET_FIX(x)
|
# define BOOST_FUNCTION_TARGET_FIX(x)
|
||||||
#endif // __ICL etc
|
#endif // not MSVC
|
||||||
|
|
||||||
|
#if !BOOST_WORKAROUND(__BORLANDC__, < 0x5A0)
|
||||||
# define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
# define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
||||||
typename ::boost::enable_if_c< \
|
typename ::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||||
!(::boost::is_integral<Functor>::value), \
|
(::boost::is_integral<Functor>::value)>::value), \
|
||||||
Type>::type
|
Type>::type
|
||||||
|
#else
|
||||||
|
// BCC doesn't recognize this depends on a template argument and complains
|
||||||
|
// about the use of 'typename'
|
||||||
|
# define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
|
||||||
|
::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||||
|
(::boost::is_integral<Functor>::value)>::value), \
|
||||||
|
Type>::type
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@@ -284,7 +294,7 @@ namespace boost {
|
|||||||
} else if (op == destroy_functor_tag)
|
} else if (op == destroy_functor_tag)
|
||||||
out_buffer.func_ptr = 0;
|
out_buffer.func_ptr = 0;
|
||||||
else if (op == check_functor_type_tag) {
|
else if (op == check_functor_type_tag) {
|
||||||
const boost::detail::sp_typeinfo& check_type
|
const detail::sp_typeinfo& check_type
|
||||||
= *out_buffer.type.type;
|
= *out_buffer.type.type;
|
||||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
|
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
|
||||||
out_buffer.obj_ptr = &in_buffer.func_ptr;
|
out_buffer.obj_ptr = &in_buffer.func_ptr;
|
||||||
@@ -651,7 +661,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
|
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||||
|
const Functor* target( Functor * = 0 ) const
|
||||||
|
#else
|
||||||
const Functor* target() const
|
const Functor* target() const
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
if (!vtable) return 0;
|
if (!vtable) return 0;
|
||||||
|
|
||||||
@@ -669,7 +683,11 @@ public:
|
|||||||
template<typename F>
|
template<typename F>
|
||||||
bool contains(const F& f) const
|
bool contains(const F& f) const
|
||||||
{
|
{
|
||||||
|
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||||
|
if (const F* fp = this->target( (F*)0 ))
|
||||||
|
#else
|
||||||
if (const F* fp = this->template target<F>())
|
if (const F* fp = this->template target<F>())
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return function_equal(*fp, f);
|
return function_equal(*fp, f);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ namespace boost { namespace python { namespace objects {
|
|||||||
}}}
|
}}}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) \
|
#if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||||
|
|| defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) \
|
||||||
|| !(defined(BOOST_STRICT_CONFIG) || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
|
|| !(defined(BOOST_STRICT_CONFIG) || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
|
||||||
# define BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
|
# define BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -26,13 +26,7 @@
|
|||||||
|
|
||||||
#define BOOST_FUNCTION_PARMS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_PARM,BOOST_PP_EMPTY)
|
#define BOOST_FUNCTION_PARMS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_PARM,BOOST_PP_EMPTY)
|
||||||
|
|
||||||
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
#define BOOST_FUNCTION_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, a)
|
||||||
# define BOOST_FUNCTION_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, a)
|
|
||||||
#else
|
|
||||||
# include <boost/move/utility_core.hpp>
|
|
||||||
# define BOOST_FUNCTION_ARG(J,I,D) ::boost::forward< BOOST_PP_CAT(T,I) >(BOOST_PP_CAT(a,I))
|
|
||||||
# define BOOST_FUNCTION_ARGS BOOST_PP_ENUM(BOOST_FUNCTION_NUM_ARGS,BOOST_FUNCTION_ARG,BOOST_PP_EMPTY)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BOOST_FUNCTION_ARG_TYPE(J,I,D) \
|
#define BOOST_FUNCTION_ARG_TYPE(J,I,D) \
|
||||||
typedef BOOST_PP_CAT(T,I) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(I)),_type);
|
typedef BOOST_PP_CAT(T,I) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(I)),_type);
|
||||||
@@ -683,7 +677,7 @@ namespace boost {
|
|||||||
|
|
||||||
vtable_type* get_vtable() const {
|
vtable_type* get_vtable() const {
|
||||||
return reinterpret_cast<vtable_type*>(
|
return reinterpret_cast<vtable_type*>(
|
||||||
reinterpret_cast<std::size_t>(vtable) & ~static_cast<std::size_t>(0x01));
|
reinterpret_cast<std::size_t>(vtable) & ~static_cast<size_t>(0x01));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct clear_type {};
|
struct clear_type {};
|
||||||
@@ -717,8 +711,9 @@ namespace boost {
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f
|
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
,typename boost::enable_if_c<
|
,typename enable_if_c<
|
||||||
!(is_integral<Functor>::value),
|
(boost::type_traits::ice_not<
|
||||||
|
(is_integral<Functor>::value)>::value),
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif // BOOST_NO_SFINAE
|
#endif // BOOST_NO_SFINAE
|
||||||
) :
|
) :
|
||||||
@@ -729,8 +724,9 @@ namespace boost {
|
|||||||
template<typename Functor,typename Allocator>
|
template<typename Functor,typename Allocator>
|
||||||
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a
|
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
,typename boost::enable_if_c<
|
,typename enable_if_c<
|
||||||
!(is_integral<Functor>::value),
|
(boost::type_traits::ice_not<
|
||||||
|
(is_integral<Functor>::value)>::value),
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif // BOOST_NO_SFINAE
|
#endif // BOOST_NO_SFINAE
|
||||||
) :
|
) :
|
||||||
@@ -752,14 +748,7 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
this->assign_to_own(f);
|
this->assign_to_own(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
BOOST_FUNCTION_FUNCTION(BOOST_FUNCTION_FUNCTION&& f) : function_base()
|
|
||||||
{
|
|
||||||
this->move_assign(f);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
~BOOST_FUNCTION_FUNCTION() { clear(); }
|
~BOOST_FUNCTION_FUNCTION() { clear(); }
|
||||||
|
|
||||||
result_type operator()(BOOST_FUNCTION_PARMS) const
|
result_type operator()(BOOST_FUNCTION_PARMS) const
|
||||||
@@ -778,8 +767,9 @@ namespace boost {
|
|||||||
// construct.
|
// construct.
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
typename boost::enable_if_c<
|
typename enable_if_c<
|
||||||
!(is_integral<Functor>::value),
|
(boost::type_traits::ice_not<
|
||||||
|
(is_integral<Functor>::value)>::value),
|
||||||
BOOST_FUNCTION_FUNCTION&>::type
|
BOOST_FUNCTION_FUNCTION&>::type
|
||||||
#else
|
#else
|
||||||
BOOST_FUNCTION_FUNCTION&
|
BOOST_FUNCTION_FUNCTION&
|
||||||
@@ -840,26 +830,6 @@ namespace boost {
|
|||||||
BOOST_CATCH_END
|
BOOST_CATCH_END
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
// Move assignment from another BOOST_FUNCTION_FUNCTION
|
|
||||||
BOOST_FUNCTION_FUNCTION& operator=(BOOST_FUNCTION_FUNCTION&& f)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (&f == this)
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
this->clear();
|
|
||||||
BOOST_TRY {
|
|
||||||
this->move_assign(f);
|
|
||||||
} BOOST_CATCH (...) {
|
|
||||||
vtable = 0;
|
|
||||||
BOOST_RETHROW;
|
|
||||||
}
|
|
||||||
BOOST_CATCH_END
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void swap(BOOST_FUNCTION_FUNCTION& other)
|
void swap(BOOST_FUNCTION_FUNCTION& other)
|
||||||
{
|
{
|
||||||
@@ -917,10 +887,10 @@ namespace boost {
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void assign_to(Functor f)
|
void assign_to(Functor f)
|
||||||
{
|
{
|
||||||
using boost::detail::function::vtable_base;
|
using detail::function::vtable_base;
|
||||||
|
|
||||||
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
||||||
typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
typedef detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||||
typedef typename get_invoker::
|
typedef typename get_invoker::
|
||||||
template apply<Functor, R BOOST_FUNCTION_COMMA
|
template apply<Functor, R BOOST_FUNCTION_COMMA
|
||||||
BOOST_FUNCTION_TEMPLATE_ARGS>
|
BOOST_FUNCTION_TEMPLATE_ARGS>
|
||||||
@@ -938,12 +908,11 @@ namespace boost {
|
|||||||
|
|
||||||
if (stored_vtable.assign_to(f, functor)) {
|
if (stored_vtable.assign_to(f, functor)) {
|
||||||
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
|
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
|
||||||
// coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
|
|
||||||
if (boost::has_trivial_copy_constructor<Functor>::value &&
|
if (boost::has_trivial_copy_constructor<Functor>::value &&
|
||||||
boost::has_trivial_destructor<Functor>::value &&
|
boost::has_trivial_destructor<Functor>::value &&
|
||||||
boost::detail::function::function_allows_small_object_optimization<Functor>::value)
|
detail::function::function_allows_small_object_optimization<Functor>::value)
|
||||||
value |= static_cast<std::size_t>(0x01);
|
value |= static_cast<size_t>(0x01);
|
||||||
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
vtable = reinterpret_cast<detail::function::vtable_base *>(value);
|
||||||
} else
|
} else
|
||||||
vtable = 0;
|
vtable = 0;
|
||||||
}
|
}
|
||||||
@@ -951,10 +920,10 @@ namespace boost {
|
|||||||
template<typename Functor,typename Allocator>
|
template<typename Functor,typename Allocator>
|
||||||
void assign_to_a(Functor f,Allocator a)
|
void assign_to_a(Functor f,Allocator a)
|
||||||
{
|
{
|
||||||
using boost::detail::function::vtable_base;
|
using detail::function::vtable_base;
|
||||||
|
|
||||||
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
||||||
typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
typedef detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||||
typedef typename get_invoker::
|
typedef typename get_invoker::
|
||||||
template apply_a<Functor, R BOOST_FUNCTION_COMMA
|
template apply_a<Functor, R BOOST_FUNCTION_COMMA
|
||||||
BOOST_FUNCTION_TEMPLATE_ARGS,
|
BOOST_FUNCTION_TEMPLATE_ARGS,
|
||||||
@@ -973,12 +942,11 @@ namespace boost {
|
|||||||
|
|
||||||
if (stored_vtable.assign_to_a(f, functor, a)) {
|
if (stored_vtable.assign_to_a(f, functor, a)) {
|
||||||
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
|
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
|
||||||
// coverity[pointless_expression]: suppress coverity warnings on apparant if(const).
|
|
||||||
if (boost::has_trivial_copy_constructor<Functor>::value &&
|
if (boost::has_trivial_copy_constructor<Functor>::value &&
|
||||||
boost::has_trivial_destructor<Functor>::value &&
|
boost::has_trivial_destructor<Functor>::value &&
|
||||||
boost::detail::function::function_allows_small_object_optimization<Functor>::value)
|
detail::function::function_allows_small_object_optimization<Functor>::value)
|
||||||
value |= static_cast<std::size_t>(0x01);
|
value |= static_cast<std::size_t>(0x01);
|
||||||
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
vtable = reinterpret_cast<detail::function::vtable_base *>(value);
|
||||||
} else
|
} else
|
||||||
vtable = 0;
|
vtable = 0;
|
||||||
}
|
}
|
||||||
@@ -1065,8 +1033,9 @@ public:
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
function(Functor f
|
function(Functor f
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
,typename boost::enable_if_c<
|
,typename enable_if_c<
|
||||||
!(is_integral<Functor>::value),
|
(boost::type_traits::ice_not<
|
||||||
|
(is_integral<Functor>::value)>::value),
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif
|
#endif
|
||||||
) :
|
) :
|
||||||
@@ -1076,8 +1045,9 @@ public:
|
|||||||
template<typename Functor,typename Allocator>
|
template<typename Functor,typename Allocator>
|
||||||
function(Functor f, Allocator a
|
function(Functor f, Allocator a
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
,typename boost::enable_if_c<
|
,typename enable_if_c<
|
||||||
!(is_integral<Functor>::value),
|
(boost::type_traits::ice_not<
|
||||||
|
(is_integral<Functor>::value)>::value),
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif
|
#endif
|
||||||
) :
|
) :
|
||||||
@@ -1093,30 +1063,17 @@ public:
|
|||||||
|
|
||||||
function(const base_type& f) : base_type(static_cast<const base_type&>(f)){}
|
function(const base_type& f) : base_type(static_cast<const base_type&>(f)){}
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
// Move constructors
|
|
||||||
function(self_type&& f): base_type(static_cast<base_type&&>(f)){}
|
|
||||||
function(base_type&& f): base_type(static_cast<base_type&&>(f)){}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
self_type& operator=(const self_type& f)
|
self_type& operator=(const self_type& f)
|
||||||
{
|
{
|
||||||
self_type(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
self_type& operator=(self_type&& f)
|
|
||||||
{
|
|
||||||
self_type(static_cast<self_type&&>(f)).swap(*this);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
typename boost::enable_if_c<
|
typename enable_if_c<
|
||||||
!(is_integral<Functor>::value),
|
(boost::type_traits::ice_not<
|
||||||
|
(is_integral<Functor>::value)>::value),
|
||||||
self_type&>::type
|
self_type&>::type
|
||||||
#else
|
#else
|
||||||
self_type&
|
self_type&
|
||||||
@@ -1140,14 +1097,6 @@ public:
|
|||||||
self_type(f).swap(*this);
|
self_type(f).swap(*this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
self_type& operator=(base_type&& f)
|
|
||||||
{
|
|
||||||
self_type(static_cast<base_type&&>(f)).swap(*this);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef BOOST_FUNCTION_PARTIAL_SPEC
|
#undef BOOST_FUNCTION_PARTIAL_SPEC
|
||||||
@@ -1176,9 +1125,6 @@ public:
|
|||||||
#undef BOOST_FUNCTION_TEMPLATE_ARGS
|
#undef BOOST_FUNCTION_TEMPLATE_ARGS
|
||||||
#undef BOOST_FUNCTION_PARMS
|
#undef BOOST_FUNCTION_PARMS
|
||||||
#undef BOOST_FUNCTION_PARM
|
#undef BOOST_FUNCTION_PARM
|
||||||
#ifdef BOOST_FUNCTION_ARG
|
|
||||||
# undef BOOST_FUNCTION_ARG
|
|
||||||
#endif
|
|
||||||
#undef BOOST_FUNCTION_ARGS
|
#undef BOOST_FUNCTION_ARGS
|
||||||
#undef BOOST_FUNCTION_ARG_TYPE
|
#undef BOOST_FUNCTION_ARG_TYPE
|
||||||
#undef BOOST_FUNCTION_ARG_TYPES
|
#undef BOOST_FUNCTION_ARG_TYPES
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"key": "function",
|
|
||||||
"name": "Function",
|
|
||||||
"authors": [
|
|
||||||
"Doug Gregor"
|
|
||||||
],
|
|
||||||
"description": "Function object wrappers for deferred calls or callbacks.",
|
|
||||||
"std": [
|
|
||||||
"tr1"
|
|
||||||
],
|
|
||||||
"category": [
|
|
||||||
"Function-objects",
|
|
||||||
"Programming"
|
|
||||||
],
|
|
||||||
"maintainers": [
|
|
||||||
"Douglas Gregor <dgregor -at- cs.indiana.edu>"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -61,8 +61,6 @@ import testing ;
|
|||||||
|
|
||||||
[ run libs/function/test/nothrow_swap.cpp : : : : ]
|
[ run libs/function/test/nothrow_swap.cpp : : : : ]
|
||||||
|
|
||||||
[ run libs/function/test/rvalues_test.cpp : : : : ]
|
|
||||||
|
|
||||||
[ compile libs/function/test/function_typeof_test.cpp ]
|
[ compile libs/function/test/function_typeof_test.cpp ]
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -690,95 +690,6 @@ static void test_call()
|
|||||||
test_call_cref(std::plus<int>());
|
test_call_cref(std::plus<int>());
|
||||||
}
|
}
|
||||||
|
|
||||||
struct big_aggregating_structure {
|
|
||||||
int disable_small_objects_optimizations[32];
|
|
||||||
|
|
||||||
big_aggregating_structure()
|
|
||||||
{
|
|
||||||
++ global_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
big_aggregating_structure(const big_aggregating_structure&)
|
|
||||||
{
|
|
||||||
++ global_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
~big_aggregating_structure()
|
|
||||||
{
|
|
||||||
-- global_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()()
|
|
||||||
{
|
|
||||||
++ global_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()(int)
|
|
||||||
{
|
|
||||||
++ global_int;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class FunctionT>
|
|
||||||
static void test_move_semantics()
|
|
||||||
{
|
|
||||||
typedef FunctionT f1_type;
|
|
||||||
|
|
||||||
big_aggregating_structure obj;
|
|
||||||
|
|
||||||
f1_type f1 = obj;
|
|
||||||
global_int = 0;
|
|
||||||
f1();
|
|
||||||
|
|
||||||
BOOST_CHECK(!f1.empty());
|
|
||||||
BOOST_CHECK(global_int == 1);
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
// Testing rvalue constructors
|
|
||||||
f1_type f2(static_cast<f1_type&&>(f1));
|
|
||||||
BOOST_CHECK(f1.empty());
|
|
||||||
BOOST_CHECK(!f2.empty());
|
|
||||||
BOOST_CHECK(global_int == 1);
|
|
||||||
f2();
|
|
||||||
BOOST_CHECK(global_int == 2);
|
|
||||||
|
|
||||||
f1_type f3(static_cast<f1_type&&>(f2));
|
|
||||||
BOOST_CHECK(f1.empty());
|
|
||||||
BOOST_CHECK(f2.empty());
|
|
||||||
BOOST_CHECK(!f3.empty());
|
|
||||||
BOOST_CHECK(global_int == 2);
|
|
||||||
f3();
|
|
||||||
BOOST_CHECK(global_int == 3);
|
|
||||||
|
|
||||||
// Testing move assignment
|
|
||||||
f1_type f4;
|
|
||||||
BOOST_CHECK(f4.empty());
|
|
||||||
f4 = static_cast<f1_type&&>(f3);
|
|
||||||
BOOST_CHECK(f1.empty());
|
|
||||||
BOOST_CHECK(f2.empty());
|
|
||||||
BOOST_CHECK(f3.empty());
|
|
||||||
BOOST_CHECK(!f4.empty());
|
|
||||||
BOOST_CHECK(global_int == 3);
|
|
||||||
f4();
|
|
||||||
BOOST_CHECK(global_int == 4);
|
|
||||||
|
|
||||||
// Testing self move assignment
|
|
||||||
f4 = static_cast<f1_type&&>(f4);
|
|
||||||
BOOST_CHECK(!f4.empty());
|
|
||||||
BOOST_CHECK(global_int == 4);
|
|
||||||
|
|
||||||
// Testing, that no memory leaked when assigning to nonempty function
|
|
||||||
f4 = obj;
|
|
||||||
BOOST_CHECK(!f4.empty());
|
|
||||||
BOOST_CHECK(global_int == 4);
|
|
||||||
f1_type f5 = obj;
|
|
||||||
BOOST_CHECK(global_int == 5);
|
|
||||||
f4 = static_cast<f1_type&&>(f5);
|
|
||||||
BOOST_CHECK(global_int == 4);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_main(int, char* [])
|
int test_main(int, char* [])
|
||||||
{
|
{
|
||||||
test_zero_args();
|
test_zero_args();
|
||||||
@@ -791,8 +702,6 @@ int test_main(int, char* [])
|
|||||||
test_exception();
|
test_exception();
|
||||||
test_implicit();
|
test_implicit();
|
||||||
test_call();
|
test_call();
|
||||||
test_move_semantics<function<void()> >();
|
|
||||||
test_move_semantics<boost::function0<void> >();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,32 +14,24 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
struct Y {
|
|
||||||
Y(int y = 0) : y_(y) {}
|
|
||||||
bool operator==(const Y& rhs) { return y_ == rhs.y_; }
|
|
||||||
private:
|
|
||||||
int y_;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct X {
|
struct X {
|
||||||
int foo(int);
|
int foo(int);
|
||||||
Y& foo2(Y&) const;
|
std::ostream& foo2(std::ostream&) const;
|
||||||
};
|
};
|
||||||
int X::foo(int x) { return -x; }
|
int X::foo(int x) { return -x; }
|
||||||
Y& X::foo2(Y& x) const { return x; }
|
std::ostream& X::foo2(std::ostream& x) const { return x; }
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
boost::function<int (X*, int)> f;
|
boost::function<int (X*, int)> f;
|
||||||
boost::function<Y& (X*, Y&)> f2;
|
boost::function<std::ostream& (X*, std::ostream&)> f2;
|
||||||
Y y1;
|
|
||||||
|
|
||||||
f = &X::foo;
|
f = &X::foo;
|
||||||
f2 = &X::foo2;
|
f2 = &X::foo2;
|
||||||
|
|
||||||
X x;
|
X x;
|
||||||
BOOST_TEST(f(&x, 5) == -5);
|
BOOST_TEST(f(&x, 5) == -5);
|
||||||
BOOST_TEST(f2(&x, boost::ref(y1)) == y1);
|
BOOST_TEST(f2(&x, boost::ref(std::cout)) == std::cout);
|
||||||
|
|
||||||
return ::boost::report_errors();
|
return ::boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,32 +14,24 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
struct Y {
|
|
||||||
Y(int y = 0) : y_(y) {}
|
|
||||||
bool operator==(const Y& rhs) { return y_ == rhs.y_; }
|
|
||||||
private:
|
|
||||||
int y_;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct X {
|
struct X {
|
||||||
int foo(int);
|
int foo(int);
|
||||||
Y& foo2(Y&) const;
|
std::ostream& foo2(std::ostream&) const;
|
||||||
};
|
};
|
||||||
int X::foo(int x) { return -x; }
|
int X::foo(int x) { return -x; }
|
||||||
Y& X::foo2(Y& x) const { return x; }
|
std::ostream& X::foo2(std::ostream& x) const { return x; }
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
boost::function2<int, X*, int> f;
|
boost::function2<int, X*, int> f;
|
||||||
boost::function2<Y&, X*, Y&> f2;
|
boost::function2<std::ostream&, X*, std::ostream&> f2;
|
||||||
Y y1;
|
|
||||||
|
|
||||||
f = &X::foo;
|
f = &X::foo;
|
||||||
f2 = &X::foo2;
|
f2 = &X::foo2;
|
||||||
|
|
||||||
X x;
|
X x;
|
||||||
BOOST_TEST(f(&x, 5) == -5);
|
BOOST_TEST(f(&x, 5) == -5);
|
||||||
BOOST_TEST(f2(&x, boost::ref(y1)) == y1);
|
BOOST_TEST(f2(&x, boost::ref(std::cout)) == std::cout);
|
||||||
|
|
||||||
return ::boost::report_errors();
|
return ::boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
// Copyright 2014 Antony Polukhin.
|
|
||||||
//
|
|
||||||
// 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 <iostream>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#include <boost/test/minimal.hpp>
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/move/move.hpp>
|
|
||||||
|
|
||||||
class only_movable {
|
|
||||||
private:
|
|
||||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(only_movable)
|
|
||||||
int value_;
|
|
||||||
bool moved_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
only_movable(BOOST_RV_REF(only_movable) x)
|
|
||||||
: value_(x.value_)
|
|
||||||
, moved_(false)
|
|
||||||
{
|
|
||||||
x.moved_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
only_movable& operator=(BOOST_RV_REF(only_movable) x) {
|
|
||||||
value_ = x.value_;
|
|
||||||
x.moved_ = true;
|
|
||||||
moved_ = false;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit only_movable(int value = 0) : value_(value), moved_(false) {}
|
|
||||||
int get_value() const { return value_; }
|
|
||||||
bool is_moved() const { return moved_; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int one(BOOST_RV_REF(only_movable) v) { return v.get_value(); }
|
|
||||||
only_movable two(BOOST_RV_REF(only_movable) t) {
|
|
||||||
only_movable t1 = boost::move(t);
|
|
||||||
return BOOST_MOVE_RET(only_movable, t1);
|
|
||||||
}
|
|
||||||
|
|
||||||
only_movable two_sum(BOOST_RV_REF(only_movable) t1, BOOST_RV_REF(only_movable) t2) {
|
|
||||||
only_movable ret(t1.get_value() + t2.get_value());
|
|
||||||
return BOOST_MOVE_RET(only_movable, ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sum_struct {
|
|
||||||
only_movable operator()(BOOST_RV_REF(only_movable) t1, BOOST_RV_REF(only_movable) t2) const {
|
|
||||||
only_movable ret(t1.get_value() + t2.get_value());
|
|
||||||
return BOOST_MOVE_RET(only_movable, ret);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
int three(std::string&&) { return 1; }
|
|
||||||
std::string&& four(std::string&& s) { return boost::move(s); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int test_main(int, char*[])
|
|
||||||
{
|
|
||||||
using boost::function;
|
|
||||||
|
|
||||||
function <int(BOOST_RV_REF(only_movable))> f1 = one;
|
|
||||||
|
|
||||||
only_movable om1(1);
|
|
||||||
BOOST_CHECK(f1(boost::move(om1)) == 1);
|
|
||||||
|
|
||||||
function <only_movable(BOOST_RV_REF(only_movable))> f2 = two;
|
|
||||||
|
|
||||||
only_movable om2(2);
|
|
||||||
only_movable om2_2 = f2(boost::move(om2));
|
|
||||||
BOOST_CHECK(om2_2.get_value() == 2);
|
|
||||||
BOOST_CHECK(om2.is_moved());
|
|
||||||
|
|
||||||
{
|
|
||||||
function <only_movable(BOOST_RV_REF(only_movable), BOOST_RV_REF(only_movable))> f2_sum = two_sum;
|
|
||||||
only_movable om1_sum(1), om2_sum(2);
|
|
||||||
only_movable om2_sum_2 = f2_sum(boost::move(om1_sum), boost::move(om2_sum));
|
|
||||||
BOOST_CHECK(om2_sum_2.get_value() == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
sum_struct s;
|
|
||||||
function <only_movable(BOOST_RV_REF(only_movable), BOOST_RV_REF(only_movable))> f2_sum = s;
|
|
||||||
only_movable om1_sum(1), om2_sum(2);
|
|
||||||
only_movable om2_sum_2 = f2_sum(boost::move(om1_sum), boost::move(om2_sum));
|
|
||||||
BOOST_CHECK(om2_sum_2.get_value() == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
|
||||||
function <int(std::string&&)> f3 = three;
|
|
||||||
function <std::string&& (std::string&& s)> f4 = four;
|
|
||||||
|
|
||||||
f3(std::string("Hello"));
|
|
||||||
BOOST_CHECK(f4(std::string("world")) == "world");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user