mirror of
https://github.com/boostorg/function.git
synced 2026-01-29 19:42:09 +00:00
Compare commits
67 Commits
sandbox-br
...
boost-1.59
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42f2a7c714 | ||
|
|
45ec47542c | ||
|
|
0c467707d9 | ||
|
|
f0ec326eb0 | ||
|
|
fde855afb0 | ||
|
|
73e4d02b00 | ||
|
|
001fcff9b8 | ||
|
|
8cc1be159b | ||
|
|
74c9cc9680 | ||
|
|
675d955364 | ||
|
|
854f2e8d5d | ||
|
|
157aaeaf23 | ||
|
|
df1db75294 | ||
|
|
27e9e1e372 | ||
|
|
8f8cdae988 | ||
|
|
02abccd686 | ||
|
|
c4aa569cf4 | ||
|
|
e38382d33e | ||
|
|
78f1bcc4b4 | ||
|
|
f3d01c47bb | ||
|
|
78eb6b1c8c | ||
|
|
a80ac7f5c5 | ||
|
|
e9fe0b6db3 | ||
|
|
9f06e35e8d | ||
|
|
250655ad6d | ||
|
|
ea19e9e745 | ||
|
|
8d5a27fb85 | ||
|
|
8760088d44 | ||
|
|
9245ac2a8f | ||
|
|
26d278733f | ||
|
|
62cce2aaaf | ||
|
|
95a1956397 | ||
|
|
352cb183fe | ||
|
|
74a61f0252 | ||
|
|
9e30736439 | ||
|
|
3ac49dc978 | ||
|
|
1ebe83a832 | ||
|
|
419f424959 | ||
|
|
bfde71273b | ||
|
|
0dc186d891 | ||
|
|
b31584cfb5 | ||
|
|
3193df71b9 | ||
|
|
f85a3db133 | ||
|
|
a0286a58c7 | ||
|
|
1b6a5673cb | ||
|
|
24a7ce00a8 | ||
|
|
c398dfceb3 | ||
|
|
a108a1cf26 | ||
|
|
d68cc8a51c | ||
|
|
cca7b35712 | ||
|
|
9bb12ce87a | ||
|
|
467ae9613f | ||
|
|
2fd383cd2e | ||
|
|
587658b047 | ||
|
|
83309a36c7 | ||
|
|
bfdb5b161d | ||
|
|
c4539395fe | ||
|
|
6147e7ddcc | ||
|
|
1b60e82b2f | ||
|
|
7581949360 | ||
|
|
0b2aeda226 | ||
|
|
2ecd62c612 | ||
|
|
47033bd162 | ||
|
|
c7d5016022 | ||
|
|
d92355cca2 | ||
|
|
0123f84bff | ||
|
|
0207da8008 |
@@ -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 boost/doc ;
|
project function/doc ;
|
||||||
import boostbook : boostbook ;
|
import boostbook : boostbook ;
|
||||||
|
|
||||||
boostbook function-doc
|
boostbook function-doc
|
||||||
|
|||||||
@@ -13,6 +13,15 @@
|
|||||||
|
|
||||||
<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><T></code>
|
<code><classname>boost::is_stateless</classname><F></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,6 +203,15 @@
|
|||||||
<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"/>
|
||||||
@@ -237,6 +246,15 @@
|
|||||||
<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">
|
||||||
<type>void</type>
|
<type>void</type>
|
||||||
@@ -608,6 +626,15 @@
|
|||||||
<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>
|
||||||
@@ -616,6 +643,15 @@
|
|||||||
<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"/>
|
||||||
@@ -645,11 +681,20 @@
|
|||||||
|
|
||||||
<copy-assignment>
|
<copy-assignment>
|
||||||
<parameter name="f">
|
<parameter name="f">
|
||||||
<paramtype>const <classname>function</classname>&</paramtype>
|
<paramtype>const <classname>functionN</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">
|
||||||
<paramtype>const <classname>function</classname>&</paramtype>
|
<paramtype>const <classname>function</classname>&</paramtype>
|
||||||
@@ -658,6 +703,15 @@
|
|||||||
<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">
|
||||||
<type>void</type>
|
<type>void</type>
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#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>
|
||||||
@@ -56,7 +55,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__) && __GNUC__ >= 3) \
|
#elif defined(__GNUC__) \
|
||||||
|| defined(_AIX) \
|
|| defined(_AIX) \
|
||||||
|| ( defined(__sgi) && defined(__host_mips))
|
|| ( defined(__sgi) && defined(__host_mips))
|
||||||
# include <cstring>
|
# include <cstring>
|
||||||
@@ -66,25 +65,16 @@
|
|||||||
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__ICL) && __ICL <= 600 || defined(__MWERKS__) && __MWERKS__ < 0x2406 && !defined(BOOST_STRICT_CONFIG)
|
#if 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 // not MSVC
|
#endif // __ICL etc
|
||||||
|
|
||||||
#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<(::boost::type_traits::ice_not< \
|
typename ::boost::enable_if_c< \
|
||||||
(::boost::is_integral<Functor>::value)>::value), \
|
!(::boost::is_integral<Functor>::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 {
|
||||||
@@ -294,7 +284,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 detail::sp_typeinfo& check_type
|
const boost::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;
|
||||||
@@ -661,11 +651,7 @@ 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;
|
||||||
|
|
||||||
@@ -683,11 +669,7 @@ 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,8 +19,7 @@ namespace boost { namespace python { namespace objects {
|
|||||||
}}}
|
}}}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
#if defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) \
|
||||||
|| 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,7 +26,13 @@
|
|||||||
|
|
||||||
#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)
|
||||||
|
|
||||||
#define BOOST_FUNCTION_ARGS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, a)
|
#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||||
|
# 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);
|
||||||
@@ -677,7 +683,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<size_t>(0x01));
|
reinterpret_cast<std::size_t>(vtable) & ~static_cast<std::size_t>(0x01));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct clear_type {};
|
struct clear_type {};
|
||||||
@@ -711,9 +717,8 @@ 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 enable_if_c<
|
,typename boost::enable_if_c<
|
||||||
(boost::type_traits::ice_not<
|
!(is_integral<Functor>::value),
|
||||||
(is_integral<Functor>::value)>::value),
|
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif // BOOST_NO_SFINAE
|
#endif // BOOST_NO_SFINAE
|
||||||
) :
|
) :
|
||||||
@@ -724,9 +729,8 @@ 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 enable_if_c<
|
,typename boost::enable_if_c<
|
||||||
(boost::type_traits::ice_not<
|
!(is_integral<Functor>::value),
|
||||||
(is_integral<Functor>::value)>::value),
|
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif // BOOST_NO_SFINAE
|
#endif // BOOST_NO_SFINAE
|
||||||
) :
|
) :
|
||||||
@@ -749,6 +753,13 @@ 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
|
||||||
@@ -767,9 +778,8 @@ namespace boost {
|
|||||||
// construct.
|
// construct.
|
||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
typename enable_if_c<
|
typename boost::enable_if_c<
|
||||||
(boost::type_traits::ice_not<
|
!(is_integral<Functor>::value),
|
||||||
(is_integral<Functor>::value)>::value),
|
|
||||||
BOOST_FUNCTION_FUNCTION&>::type
|
BOOST_FUNCTION_FUNCTION&>::type
|
||||||
#else
|
#else
|
||||||
BOOST_FUNCTION_FUNCTION&
|
BOOST_FUNCTION_FUNCTION&
|
||||||
@@ -831,6 +841,26 @@ namespace boost {
|
|||||||
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)
|
||||||
{
|
{
|
||||||
if (&other == this)
|
if (&other == this)
|
||||||
@@ -887,10 +917,10 @@ namespace boost {
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
void assign_to(Functor f)
|
void assign_to(Functor f)
|
||||||
{
|
{
|
||||||
using detail::function::vtable_base;
|
using boost::detail::function::vtable_base;
|
||||||
|
|
||||||
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
||||||
typedef detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
typedef boost::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>
|
||||||
@@ -908,11 +938,12 @@ 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 &&
|
||||||
detail::function::function_allows_small_object_optimization<Functor>::value)
|
boost::detail::function::function_allows_small_object_optimization<Functor>::value)
|
||||||
value |= static_cast<size_t>(0x01);
|
value |= static_cast<std::size_t>(0x01);
|
||||||
vtable = reinterpret_cast<detail::function::vtable_base *>(value);
|
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
||||||
} else
|
} else
|
||||||
vtable = 0;
|
vtable = 0;
|
||||||
}
|
}
|
||||||
@@ -920,10 +951,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 detail::function::vtable_base;
|
using boost::detail::function::vtable_base;
|
||||||
|
|
||||||
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
||||||
typedef detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
typedef boost::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,
|
||||||
@@ -942,11 +973,12 @@ 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 &&
|
||||||
detail::function::function_allows_small_object_optimization<Functor>::value)
|
boost::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<detail::function::vtable_base *>(value);
|
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
||||||
} else
|
} else
|
||||||
vtable = 0;
|
vtable = 0;
|
||||||
}
|
}
|
||||||
@@ -1033,9 +1065,8 @@ public:
|
|||||||
template<typename Functor>
|
template<typename Functor>
|
||||||
function(Functor f
|
function(Functor f
|
||||||
#ifndef BOOST_NO_SFINAE
|
#ifndef BOOST_NO_SFINAE
|
||||||
,typename enable_if_c<
|
,typename boost::enable_if_c<
|
||||||
(boost::type_traits::ice_not<
|
!(is_integral<Functor>::value),
|
||||||
(is_integral<Functor>::value)>::value),
|
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif
|
#endif
|
||||||
) :
|
) :
|
||||||
@@ -1045,9 +1076,8 @@ 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 enable_if_c<
|
,typename boost::enable_if_c<
|
||||||
(boost::type_traits::ice_not<
|
!(is_integral<Functor>::value),
|
||||||
(is_integral<Functor>::value)>::value),
|
|
||||||
int>::type = 0
|
int>::type = 0
|
||||||
#endif
|
#endif
|
||||||
) :
|
) :
|
||||||
@@ -1063,17 +1093,30 @@ 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 enable_if_c<
|
typename boost::enable_if_c<
|
||||||
(boost::type_traits::ice_not<
|
!(is_integral<Functor>::value),
|
||||||
(is_integral<Functor>::value)>::value),
|
|
||||||
self_type&>::type
|
self_type&>::type
|
||||||
#else
|
#else
|
||||||
self_type&
|
self_type&
|
||||||
@@ -1097,6 +1140,14 @@ 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
|
||||||
@@ -1125,6 +1176,9 @@ 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
|
||||||
|
|||||||
18
meta/libraries.json
Normal file
18
meta/libraries.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"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,6 +61,8 @@ 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,6 +690,95 @@ 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();
|
||||||
@@ -702,6 +791,8 @@ 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,24 +14,32 @@
|
|||||||
#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);
|
||||||
std::ostream& foo2(std::ostream&) const;
|
Y& foo2(Y&) const;
|
||||||
};
|
};
|
||||||
int X::foo(int x) { return -x; }
|
int X::foo(int x) { return -x; }
|
||||||
std::ostream& X::foo2(std::ostream& x) const { return x; }
|
Y& X::foo2(Y& x) const { return x; }
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
boost::function<int (X*, int)> f;
|
boost::function<int (X*, int)> f;
|
||||||
boost::function<std::ostream& (X*, std::ostream&)> f2;
|
boost::function<Y& (X*, Y&)> 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(std::cout)) == std::cout);
|
BOOST_TEST(f2(&x, boost::ref(y1)) == y1);
|
||||||
|
|
||||||
return ::boost::report_errors();
|
return ::boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,24 +14,32 @@
|
|||||||
#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);
|
||||||
std::ostream& foo2(std::ostream&) const;
|
Y& foo2(Y&) const;
|
||||||
};
|
};
|
||||||
int X::foo(int x) { return -x; }
|
int X::foo(int x) { return -x; }
|
||||||
std::ostream& X::foo2(std::ostream& x) const { return x; }
|
Y& X::foo2(Y& x) const { return x; }
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
boost::function2<int, X*, int> f;
|
boost::function2<int, X*, int> f;
|
||||||
boost::function2<std::ostream&, X*, std::ostream&> f2;
|
boost::function2<Y&, X*, Y&> 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(std::cout)) == std::cout);
|
BOOST_TEST(f2(&x, boost::ref(y1)) == y1);
|
||||||
|
|
||||||
return ::boost::report_errors();
|
return ::boost::report_errors();
|
||||||
}
|
}
|
||||||
|
|||||||
106
test/rvalues_test.cpp
Normal file
106
test/rvalues_test.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
// 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