mirror of
https://github.com/boostorg/function.git
synced 2025-06-25 12:01:38 +02:00
Compare commits
86 Commits
svn-branch
...
boost-1.65
Author | SHA1 | Date | |
---|---|---|---|
b84891ba9d | |||
01b81da059 | |||
a76403e102 | |||
44a68454aa | |||
0707a60115 | |||
dd04707209 | |||
0c351a9d28 | |||
79a557a340 | |||
2df73bc024 | |||
53b1ee6a75 | |||
ec2efa53ba | |||
fe093c7246 | |||
3a9161a44e | |||
fa2d6be8de | |||
c326d30f28 | |||
6976d15f74 | |||
21ad529e10 | |||
bf91c9bb3c | |||
6e98e46e7b | |||
6a24b1e59c | |||
fed32bc072 | |||
54988e8e91 | |||
bde64bf9eb | |||
3eb8954877 | |||
42f2a7c714 | |||
45ec47542c | |||
0c467707d9 | |||
f0ec326eb0 | |||
8998778f51 | |||
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 | |||
62cce2aaaf | |||
352cb183fe | |||
3ac49dc978 | |||
1ebe83a832 | |||
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 |
140
.travis.yml
Normal file
140
.travis.yml
Normal file
@ -0,0 +1,140 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
python: "2.7"
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BOGUS_JOB=true
|
||||
|
||||
matrix:
|
||||
|
||||
exclude:
|
||||
- env: BOGUS_JOB=true
|
||||
|
||||
include:
|
||||
- os: linux
|
||||
compiler: g++
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=c++03
|
||||
|
||||
- os: linux
|
||||
compiler: g++-4.7
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-5
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: g++-6
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: g++-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: linux
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.5
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.5
|
||||
|
||||
- os: linux
|
||||
compiler: clang++-3.9
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++14
|
||||
|
||||
- os: osx
|
||||
compiler: clang++
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++1z
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init tools/boostdep
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/function
|
||||
- python tools/boostdep/depinst/depinst.py function
|
||||
- ./bootstrap.sh
|
||||
- ./b2 headers
|
||||
|
||||
script:
|
||||
- |-
|
||||
echo "using $TOOLSET : : $COMPILER : <cxxflags>-std=$CXXSTD ;" > ~/user-config.jam
|
||||
- ./b2 libs/function/test toolset=$TOOLSET
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
@ -3,7 +3,7 @@
|
||||
# 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)
|
||||
project boost/doc ;
|
||||
project function/doc ;
|
||||
import boostbook : boostbook ;
|
||||
|
||||
boostbook function-doc
|
||||
@ -14,3 +14,12 @@ boostbook function-doc
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
||||
;
|
||||
|
||||
###############################################################################
|
||||
alias boostdoc
|
||||
: function.xml
|
||||
:
|
||||
:
|
||||
: ;
|
||||
explicit boostdoc ;
|
||||
alias boostrelease ;
|
||||
explicit boostrelease ;
|
||||
|
@ -128,7 +128,7 @@
|
||||
|
||||
<method name="target_type" cv="const">
|
||||
<type>const std::type_info&</type>
|
||||
<returns><simpara><code>typeid</code> of the target function object, or <code>typeid(void)</code> if <code>this-><methodname>empty</methodname>()</code>.</simpara></returns>
|
||||
<returns><simpara><code>typeid</code> of the target function object, or <code>typeid(void)</code> if <code>this-><methodname>empty</methodname>()</code>. Works even with RTTI off.</simpara></returns>
|
||||
<throws><simpara>Will not throw.</simpara></throws>
|
||||
</method>
|
||||
</method-group>
|
||||
|
@ -16,16 +16,15 @@
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/integer.hpp>
|
||||
#include <boost/type_index.hpp>
|
||||
#include <boost/type_traits/has_trivial_copy.hpp>
|
||||
#include <boost/type_traits/has_trivial_destructor.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/is_volatile.hpp>
|
||||
#include <boost/type_traits/composite_traits.hpp>
|
||||
#include <boost/type_traits/ice.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
@ -42,49 +41,18 @@
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable : 4793 ) // complaint about native code generation
|
||||
# pragma warning( disable : 4127 ) // "conditional expression is constant"
|
||||
#endif
|
||||
|
||||
// Define BOOST_FUNCTION_STD_NS to the namespace that contains type_info.
|
||||
#ifdef BOOST_NO_STD_TYPEINFO
|
||||
// Embedded VC++ does not have type_info in namespace std
|
||||
# define BOOST_FUNCTION_STD_NS
|
||||
#else
|
||||
# define BOOST_FUNCTION_STD_NS std
|
||||
#endif
|
||||
|
||||
// Borrowed from Boost.Python library: determines the cases where we
|
||||
// need to use std::type_info::name to compare instead of operator==.
|
||||
#if defined( BOOST_NO_TYPEID )
|
||||
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
||||
#elif (defined(__GNUC__) && __GNUC__ >= 3) \
|
||||
|| defined(_AIX) \
|
||||
|| ( defined(__sgi) && defined(__host_mips))
|
||||
# include <cstring>
|
||||
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) \
|
||||
(std::strcmp((X).name(),(Y).name()) == 0)
|
||||
# else
|
||||
# define BOOST_FUNCTION_COMPARE_TYPE_ID(X,Y) ((X)==(Y))
|
||||
#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
|
||||
#else
|
||||
# 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) \
|
||||
typename ::boost::enable_if_c<(::boost::type_traits::ice_not< \
|
||||
(::boost::is_integral<Functor>::value)>::value), \
|
||||
typename ::boost::enable_if_c< \
|
||||
!(::boost::is_integral<Functor>::value), \
|
||||
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 detail {
|
||||
@ -97,15 +65,16 @@ namespace boost {
|
||||
* object pointers, and a structure that resembles a bound
|
||||
* member function pointer.
|
||||
*/
|
||||
union function_buffer
|
||||
union function_buffer_members
|
||||
{
|
||||
// For pointers to function objects
|
||||
mutable void* obj_ptr;
|
||||
typedef void* obj_ptr_t;
|
||||
mutable obj_ptr_t obj_ptr;
|
||||
|
||||
// For pointers to std::type_info objects
|
||||
struct type_t {
|
||||
// (get_functor_type_tag, check_functor_type_tag).
|
||||
const detail::sp_typeinfo* type;
|
||||
const boost::typeindex::type_info* type;
|
||||
|
||||
// Whether the type is const-qualified.
|
||||
bool const_qualified;
|
||||
@ -114,7 +83,8 @@ namespace boost {
|
||||
} type;
|
||||
|
||||
// For function pointers of all kinds
|
||||
mutable void (*func_ptr)();
|
||||
typedef void (*func_ptr_t)();
|
||||
mutable func_ptr_t func_ptr;
|
||||
|
||||
// For bound member pointers
|
||||
struct bound_memfunc_ptr_t {
|
||||
@ -129,9 +99,15 @@ namespace boost {
|
||||
bool is_const_qualified;
|
||||
bool is_volatile_qualified;
|
||||
} obj_ref;
|
||||
};
|
||||
|
||||
union function_buffer
|
||||
{
|
||||
// Type-specific union members
|
||||
mutable function_buffer_members members;
|
||||
|
||||
// To relax aliasing constraints
|
||||
mutable char data;
|
||||
mutable char data[sizeof(function_buffer_members)];
|
||||
};
|
||||
|
||||
/**
|
||||
@ -198,45 +174,42 @@ namespace boost {
|
||||
struct reference_manager
|
||||
{
|
||||
static inline void
|
||||
manage(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manage(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op)
|
||||
{
|
||||
switch (op) {
|
||||
case clone_functor_tag:
|
||||
out_buffer.obj_ref = in_buffer.obj_ref;
|
||||
case clone_functor_tag:
|
||||
out_buffer.members.obj_ref = in_buffer.members.obj_ref;
|
||||
return;
|
||||
|
||||
case move_functor_tag:
|
||||
out_buffer.obj_ref = in_buffer.obj_ref;
|
||||
in_buffer.obj_ref.obj_ptr = 0;
|
||||
out_buffer.members.obj_ref = in_buffer.members.obj_ref;
|
||||
in_buffer.members.obj_ref.obj_ptr = 0;
|
||||
return;
|
||||
|
||||
case destroy_functor_tag:
|
||||
out_buffer.obj_ref.obj_ptr = 0;
|
||||
out_buffer.members.obj_ref.obj_ptr = 0;
|
||||
return;
|
||||
|
||||
case check_functor_type_tag:
|
||||
{
|
||||
const detail::sp_typeinfo& check_type
|
||||
= *out_buffer.type.type;
|
||||
|
||||
// Check whether we have the same type. We can add
|
||||
// cv-qualifiers, but we can't take them away.
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(F))
|
||||
&& (!in_buffer.obj_ref.is_const_qualified
|
||||
|| out_buffer.type.const_qualified)
|
||||
&& (!in_buffer.obj_ref.is_volatile_qualified
|
||||
|| out_buffer.type.volatile_qualified))
|
||||
out_buffer.obj_ptr = in_buffer.obj_ref.obj_ptr;
|
||||
if (*out_buffer.members.type.type == boost::typeindex::type_id<F>()
|
||||
&& (!in_buffer.members.obj_ref.is_const_qualified
|
||||
|| out_buffer.members.type.const_qualified)
|
||||
&& (!in_buffer.members.obj_ref.is_volatile_qualified
|
||||
|| out_buffer.members.type.volatile_qualified))
|
||||
out_buffer.members.obj_ptr = in_buffer.members.obj_ref.obj_ptr;
|
||||
else
|
||||
out_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = 0;
|
||||
}
|
||||
return;
|
||||
|
||||
case get_functor_type_tag:
|
||||
out_buffer.type.type = &BOOST_SP_TYPEID(F);
|
||||
out_buffer.type.const_qualified = in_buffer.obj_ref.is_const_qualified;
|
||||
out_buffer.type.volatile_qualified = in_buffer.obj_ref.is_volatile_qualified;
|
||||
out_buffer.members.type.type = &boost::typeindex::type_id<F>().type_info();
|
||||
out_buffer.members.type.const_qualified = in_buffer.members.obj_ref.is_const_qualified;
|
||||
out_buffer.members.type.volatile_qualified = in_buffer.members.obj_ref.is_volatile_qualified;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -250,9 +223,9 @@ namespace boost {
|
||||
struct function_allows_small_object_optimization
|
||||
{
|
||||
BOOST_STATIC_CONSTANT
|
||||
(bool,
|
||||
(bool,
|
||||
value = ((sizeof(F) <= sizeof(function_buffer) &&
|
||||
(alignment_of<function_buffer>::value
|
||||
(alignment_of<function_buffer>::value
|
||||
% alignment_of<F>::value == 0))));
|
||||
};
|
||||
|
||||
@ -264,7 +237,7 @@ namespace boost {
|
||||
A(a)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
functor_wrapper(const functor_wrapper& f) :
|
||||
F(static_cast<const F&>(f)),
|
||||
A(static_cast<const A&>(f))
|
||||
@ -283,61 +256,57 @@ namespace boost {
|
||||
|
||||
// Function pointers
|
||||
static inline void
|
||||
manage_ptr(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manage_ptr(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op)
|
||||
{
|
||||
if (op == clone_functor_tag)
|
||||
out_buffer.func_ptr = in_buffer.func_ptr;
|
||||
out_buffer.members.func_ptr = in_buffer.members.func_ptr;
|
||||
else if (op == move_functor_tag) {
|
||||
out_buffer.func_ptr = in_buffer.func_ptr;
|
||||
in_buffer.func_ptr = 0;
|
||||
out_buffer.members.func_ptr = in_buffer.members.func_ptr;
|
||||
in_buffer.members.func_ptr = 0;
|
||||
} else if (op == destroy_functor_tag)
|
||||
out_buffer.func_ptr = 0;
|
||||
out_buffer.members.func_ptr = 0;
|
||||
else if (op == check_functor_type_tag) {
|
||||
const detail::sp_typeinfo& check_type
|
||||
= *out_buffer.type.type;
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
|
||||
out_buffer.obj_ptr = &in_buffer.func_ptr;
|
||||
if (*out_buffer.members.type.type == boost::typeindex::type_id<Functor>())
|
||||
out_buffer.members.obj_ptr = &in_buffer.members.func_ptr;
|
||||
else
|
||||
out_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = 0;
|
||||
} else /* op == get_functor_type_tag */ {
|
||||
out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
|
||||
out_buffer.type.const_qualified = false;
|
||||
out_buffer.type.volatile_qualified = false;
|
||||
out_buffer.members.type.type = &boost::typeindex::type_id<Functor>().type_info();
|
||||
out_buffer.members.type.const_qualified = false;
|
||||
out_buffer.members.type.volatile_qualified = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Function objects that fit in the small-object buffer.
|
||||
static inline void
|
||||
manage_small(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manage_small(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op)
|
||||
{
|
||||
if (op == clone_functor_tag || op == move_functor_tag) {
|
||||
const functor_type* in_functor =
|
||||
reinterpret_cast<const functor_type*>(&in_buffer.data);
|
||||
new (reinterpret_cast<void*>(&out_buffer.data)) functor_type(*in_functor);
|
||||
const functor_type* in_functor =
|
||||
reinterpret_cast<const functor_type*>(in_buffer.data);
|
||||
new (reinterpret_cast<void*>(out_buffer.data)) functor_type(*in_functor);
|
||||
|
||||
if (op == move_functor_tag) {
|
||||
functor_type* f = reinterpret_cast<functor_type*>(&in_buffer.data);
|
||||
functor_type* f = reinterpret_cast<functor_type*>(in_buffer.data);
|
||||
(void)f; // suppress warning about the value of f not being used (MSVC)
|
||||
f->~Functor();
|
||||
}
|
||||
} else if (op == destroy_functor_tag) {
|
||||
// Some compilers (Borland, vc6, ...) are unhappy with ~functor_type.
|
||||
functor_type* f = reinterpret_cast<functor_type*>(&out_buffer.data);
|
||||
functor_type* f = reinterpret_cast<functor_type*>(out_buffer.data);
|
||||
(void)f; // suppress warning about the value of f not being used (MSVC)
|
||||
f->~Functor();
|
||||
} else if (op == check_functor_type_tag) {
|
||||
const detail::sp_typeinfo& check_type
|
||||
= *out_buffer.type.type;
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
|
||||
out_buffer.obj_ptr = &in_buffer.data;
|
||||
if (*out_buffer.members.type.type == boost::typeindex::type_id<Functor>())
|
||||
out_buffer.members.obj_ptr = in_buffer.data;
|
||||
else
|
||||
out_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = 0;
|
||||
} else /* op == get_functor_type_tag */ {
|
||||
out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
|
||||
out_buffer.type.const_qualified = false;
|
||||
out_buffer.type.volatile_qualified = false;
|
||||
out_buffer.members.type.type = &boost::typeindex::type_id<Functor>().type_info();
|
||||
out_buffer.members.type.const_qualified = false;
|
||||
out_buffer.members.type.volatile_qualified = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -350,7 +319,7 @@ namespace boost {
|
||||
|
||||
// Function pointers
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, function_ptr_tag)
|
||||
{
|
||||
functor_manager_common<Functor>::manage_ptr(in_buffer,out_buffer,op);
|
||||
@ -358,15 +327,15 @@ namespace boost {
|
||||
|
||||
// Function objects that fit in the small-object buffer.
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, mpl::true_)
|
||||
{
|
||||
functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op);
|
||||
}
|
||||
|
||||
|
||||
// Function objects that require heap allocation
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, mpl::false_)
|
||||
{
|
||||
if (op == clone_functor_tag) {
|
||||
@ -376,29 +345,27 @@ namespace boost {
|
||||
// jewillco: Changing this to static_cast because GCC 2.95.3 is
|
||||
// obsolete.
|
||||
const functor_type* f =
|
||||
static_cast<const functor_type*>(in_buffer.obj_ptr);
|
||||
static_cast<const functor_type*>(in_buffer.members.obj_ptr);
|
||||
functor_type* new_f = new functor_type(*f);
|
||||
out_buffer.obj_ptr = new_f;
|
||||
out_buffer.members.obj_ptr = new_f;
|
||||
} else if (op == move_functor_tag) {
|
||||
out_buffer.obj_ptr = in_buffer.obj_ptr;
|
||||
in_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = in_buffer.members.obj_ptr;
|
||||
in_buffer.members.obj_ptr = 0;
|
||||
} else if (op == destroy_functor_tag) {
|
||||
/* Cast from the void pointer to the functor pointer type */
|
||||
functor_type* f =
|
||||
static_cast<functor_type*>(out_buffer.obj_ptr);
|
||||
static_cast<functor_type*>(out_buffer.members.obj_ptr);
|
||||
delete f;
|
||||
out_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = 0;
|
||||
} else if (op == check_functor_type_tag) {
|
||||
const detail::sp_typeinfo& check_type
|
||||
= *out_buffer.type.type;
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
|
||||
out_buffer.obj_ptr = in_buffer.obj_ptr;
|
||||
if (*out_buffer.members.type.type == boost::typeindex::type_id<Functor>())
|
||||
out_buffer.members.obj_ptr = in_buffer.members.obj_ptr;
|
||||
else
|
||||
out_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = 0;
|
||||
} else /* op == get_functor_type_tag */ {
|
||||
out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
|
||||
out_buffer.type.const_qualified = false;
|
||||
out_buffer.type.volatile_qualified = false;
|
||||
out_buffer.members.type.type = &boost::typeindex::type_id<Functor>().type_info();
|
||||
out_buffer.members.type.const_qualified = false;
|
||||
out_buffer.members.type.volatile_qualified = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,7 +373,7 @@ namespace boost {
|
||||
// object can use the small-object optimization buffer or
|
||||
// whether we need to allocate it on the heap.
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, function_obj_tag)
|
||||
{
|
||||
manager(in_buffer, out_buffer, op,
|
||||
@ -415,7 +382,7 @@ namespace boost {
|
||||
|
||||
// For member pointers, we use the small-object optimization buffer.
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, member_ptr_tag)
|
||||
{
|
||||
manager(in_buffer, out_buffer, op, mpl::true_());
|
||||
@ -425,15 +392,15 @@ namespace boost {
|
||||
/* Dispatch to an appropriate manager based on whether we have a
|
||||
function pointer or a function object pointer. */
|
||||
static inline void
|
||||
manage(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manage(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op)
|
||||
{
|
||||
typedef typename get_function_tag<functor_type>::type tag_type;
|
||||
switch (op) {
|
||||
case get_functor_type_tag:
|
||||
out_buffer.type.type = &BOOST_SP_TYPEID(functor_type);
|
||||
out_buffer.type.const_qualified = false;
|
||||
out_buffer.type.volatile_qualified = false;
|
||||
out_buffer.members.type.type = &boost::typeindex::type_id<functor_type>().type_info();
|
||||
out_buffer.members.type.const_qualified = false;
|
||||
out_buffer.members.type.volatile_qualified = false;
|
||||
return;
|
||||
|
||||
default:
|
||||
@ -451,7 +418,7 @@ namespace boost {
|
||||
|
||||
// Function pointers
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, function_ptr_tag)
|
||||
{
|
||||
functor_manager_common<Functor>::manage_ptr(in_buffer,out_buffer,op);
|
||||
@ -459,15 +426,15 @@ namespace boost {
|
||||
|
||||
// Function objects that fit in the small-object buffer.
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, mpl::true_)
|
||||
{
|
||||
functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op);
|
||||
}
|
||||
|
||||
|
||||
// Function objects that require heap allocation
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, mpl::false_)
|
||||
{
|
||||
typedef functor_wrapper<Functor,Allocator> functor_wrapper_type;
|
||||
@ -480,36 +447,34 @@ namespace boost {
|
||||
// GCC 2.95.3 gets the CV qualifiers wrong here, so we
|
||||
// can't do the static_cast that we should do.
|
||||
const functor_wrapper_type* f =
|
||||
static_cast<const functor_wrapper_type*>(in_buffer.obj_ptr);
|
||||
static_cast<const functor_wrapper_type*>(in_buffer.members.obj_ptr);
|
||||
wrapper_allocator_type wrapper_allocator(static_cast<Allocator const &>(*f));
|
||||
wrapper_allocator_pointer_type copy = wrapper_allocator.allocate(1);
|
||||
wrapper_allocator.construct(copy, *f);
|
||||
|
||||
// Get back to the original pointer type
|
||||
functor_wrapper_type* new_f = static_cast<functor_wrapper_type*>(copy);
|
||||
out_buffer.obj_ptr = new_f;
|
||||
out_buffer.members.obj_ptr = new_f;
|
||||
} else if (op == move_functor_tag) {
|
||||
out_buffer.obj_ptr = in_buffer.obj_ptr;
|
||||
in_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = in_buffer.members.obj_ptr;
|
||||
in_buffer.members.obj_ptr = 0;
|
||||
} else if (op == destroy_functor_tag) {
|
||||
/* Cast from the void pointer to the functor_wrapper_type */
|
||||
functor_wrapper_type* victim =
|
||||
static_cast<functor_wrapper_type*>(in_buffer.obj_ptr);
|
||||
static_cast<functor_wrapper_type*>(in_buffer.members.obj_ptr);
|
||||
wrapper_allocator_type wrapper_allocator(static_cast<Allocator const &>(*victim));
|
||||
wrapper_allocator.destroy(victim);
|
||||
wrapper_allocator.deallocate(victim,1);
|
||||
out_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = 0;
|
||||
} else if (op == check_functor_type_tag) {
|
||||
const detail::sp_typeinfo& check_type
|
||||
= *out_buffer.type.type;
|
||||
if (BOOST_FUNCTION_COMPARE_TYPE_ID(check_type, BOOST_SP_TYPEID(Functor)))
|
||||
out_buffer.obj_ptr = in_buffer.obj_ptr;
|
||||
if (*out_buffer.members.type.type == boost::typeindex::type_id<Functor>())
|
||||
out_buffer.members.obj_ptr = in_buffer.members.obj_ptr;
|
||||
else
|
||||
out_buffer.obj_ptr = 0;
|
||||
out_buffer.members.obj_ptr = 0;
|
||||
} else /* op == get_functor_type_tag */ {
|
||||
out_buffer.type.type = &BOOST_SP_TYPEID(Functor);
|
||||
out_buffer.type.const_qualified = false;
|
||||
out_buffer.type.volatile_qualified = false;
|
||||
out_buffer.members.type.type = &boost::typeindex::type_id<Functor>().type_info();
|
||||
out_buffer.members.type.const_qualified = false;
|
||||
out_buffer.members.type.volatile_qualified = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,7 +482,7 @@ namespace boost {
|
||||
// object can use the small-object optimization buffer or
|
||||
// whether we need to allocate it on the heap.
|
||||
static inline void
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op, function_obj_tag)
|
||||
{
|
||||
manager(in_buffer, out_buffer, op,
|
||||
@ -528,15 +493,15 @@ namespace boost {
|
||||
/* Dispatch to an appropriate manager based on whether we have a
|
||||
function pointer or a function object pointer. */
|
||||
static inline void
|
||||
manage(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
manage(const function_buffer& in_buffer, function_buffer& out_buffer,
|
||||
functor_manager_operation_type op)
|
||||
{
|
||||
typedef typename get_function_tag<functor_type>::type tag_type;
|
||||
switch (op) {
|
||||
case get_functor_type_tag:
|
||||
out_buffer.type.type = &BOOST_SP_TYPEID(functor_type);
|
||||
out_buffer.type.const_qualified = false;
|
||||
out_buffer.type.volatile_qualified = false;
|
||||
out_buffer.members.type.type = &boost::typeindex::type_id<functor_type>().type_info();
|
||||
out_buffer.members.type.const_qualified = false;
|
||||
out_buffer.members.type.volatile_qualified = false;
|
||||
return;
|
||||
|
||||
default:
|
||||
@ -614,8 +579,8 @@ namespace boost {
|
||||
*/
|
||||
struct vtable_base
|
||||
{
|
||||
void (*manager)(const function_buffer& in_buffer,
|
||||
function_buffer& out_buffer,
|
||||
void (*manager)(const function_buffer& in_buffer,
|
||||
function_buffer& out_buffer,
|
||||
functor_manager_operation_type op);
|
||||
};
|
||||
} // end namespace function
|
||||
@ -635,15 +600,15 @@ public:
|
||||
/** Determine if the function is empty (i.e., has no target). */
|
||||
bool empty() const { return !vtable; }
|
||||
|
||||
/** Retrieve the type of the stored function object, or BOOST_SP_TYPEID(void)
|
||||
/** Retrieve the type of the stored function object, or type_id<void>()
|
||||
if this is empty. */
|
||||
const detail::sp_typeinfo& target_type() const
|
||||
const boost::typeindex::type_info& target_type() const
|
||||
{
|
||||
if (!vtable) return BOOST_SP_TYPEID(void);
|
||||
if (!vtable) return boost::typeindex::type_id<void>().type_info();
|
||||
|
||||
detail::function::function_buffer type;
|
||||
get_vtable()->manager(functor, type, detail::function::get_functor_type_tag);
|
||||
return *type.type.type;
|
||||
return *type.members.type.type;
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
@ -652,42 +617,34 @@ public:
|
||||
if (!vtable) return 0;
|
||||
|
||||
detail::function::function_buffer type_result;
|
||||
type_result.type.type = &BOOST_SP_TYPEID(Functor);
|
||||
type_result.type.const_qualified = is_const<Functor>::value;
|
||||
type_result.type.volatile_qualified = is_volatile<Functor>::value;
|
||||
get_vtable()->manager(functor, type_result,
|
||||
type_result.members.type.type = &boost::typeindex::type_id<Functor>().type_info();
|
||||
type_result.members.type.const_qualified = is_const<Functor>::value;
|
||||
type_result.members.type.volatile_qualified = is_volatile<Functor>::value;
|
||||
get_vtable()->manager(functor, type_result,
|
||||
detail::function::check_functor_type_tag);
|
||||
return static_cast<Functor*>(type_result.obj_ptr);
|
||||
return static_cast<Functor*>(type_result.members.obj_ptr);
|
||||
}
|
||||
|
||||
template<typename Functor>
|
||||
#if defined(BOOST_MSVC) && BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
const Functor* target( Functor * = 0 ) const
|
||||
#else
|
||||
const Functor* target() const
|
||||
#endif
|
||||
{
|
||||
if (!vtable) return 0;
|
||||
|
||||
detail::function::function_buffer type_result;
|
||||
type_result.type.type = &BOOST_SP_TYPEID(Functor);
|
||||
type_result.type.const_qualified = true;
|
||||
type_result.type.volatile_qualified = is_volatile<Functor>::value;
|
||||
get_vtable()->manager(functor, type_result,
|
||||
type_result.members.type.type = &boost::typeindex::type_id<Functor>().type_info();
|
||||
type_result.members.type.const_qualified = true;
|
||||
type_result.members.type.volatile_qualified = is_volatile<Functor>::value;
|
||||
get_vtable()->manager(functor, type_result,
|
||||
detail::function::check_functor_type_tag);
|
||||
// GCC 2.95.3 gets the CV qualifiers wrong here, so we
|
||||
// can't do the static_cast that we should do.
|
||||
return static_cast<const Functor*>(type_result.obj_ptr);
|
||||
return static_cast<const Functor*>(type_result.members.obj_ptr);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
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>())
|
||||
#endif
|
||||
{
|
||||
return function_equal(*fp, f);
|
||||
} else {
|
||||
@ -901,10 +858,9 @@ namespace detail {
|
||||
} // end namespace boost
|
||||
|
||||
#undef BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL
|
||||
#undef BOOST_FUNCTION_COMPARE_TYPE_ID
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // BOOST_FUNCTION_BASE_HEADER
|
||||
|
@ -19,8 +19,7 @@ namespace boost { namespace python { namespace objects {
|
||||
}}}
|
||||
#endif
|
||||
|
||||
#if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||
|| defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) \
|
||||
#if defined(BOOST_BCB_PARTIAL_SPECIALIZATION_BUG) \
|
||||
|| !(defined(BOOST_STRICT_CONFIG) || !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x540)
|
||||
# define BOOST_FUNCTION_NO_FUNCTION_TYPE_SYNTAX
|
||||
#endif
|
||||
|
@ -16,7 +16,7 @@
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning( push )
|
||||
# pragma warning( disable : 4127 ) // "conditional expression is constant"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define BOOST_FUNCTION_TEMPLATE_PARMS BOOST_PP_ENUM_PARAMS(BOOST_FUNCTION_NUM_ARGS, typename T)
|
||||
|
||||
@ -26,7 +26,13 @@
|
||||
|
||||
#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) \
|
||||
typedef BOOST_PP_CAT(T,I) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(I)),_type);
|
||||
@ -91,7 +97,7 @@ namespace boost {
|
||||
static R invoke(function_buffer& function_ptr BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_PARMS)
|
||||
{
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.members.func_ptr);
|
||||
return f(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
@ -108,7 +114,7 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.func_ptr);
|
||||
FunctionPtr f = reinterpret_cast<FunctionPtr>(function_ptr.members.func_ptr);
|
||||
BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
@ -126,9 +132,9 @@ namespace boost {
|
||||
{
|
||||
FunctionObj* f;
|
||||
if (function_allows_small_object_optimization<FunctionObj>::value)
|
||||
f = reinterpret_cast<FunctionObj*>(&function_obj_ptr.data);
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.data);
|
||||
else
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
return (*f)(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
@ -147,9 +153,9 @@ namespace boost {
|
||||
{
|
||||
FunctionObj* f;
|
||||
if (function_allows_small_object_optimization<FunctionObj>::value)
|
||||
f = reinterpret_cast<FunctionObj*>(&function_obj_ptr.data);
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.data);
|
||||
else
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
||||
f = reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
@ -165,8 +171,8 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
return (*f)(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
@ -183,8 +189,8 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.obj_ptr);
|
||||
FunctionObj* f =
|
||||
reinterpret_cast<FunctionObj*>(function_obj_ptr.members.obj_ptr);
|
||||
BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
@ -202,8 +208,8 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(function_obj_ptr.data);
|
||||
return boost::mem_fn(*f)(BOOST_FUNCTION_ARGS);
|
||||
}
|
||||
};
|
||||
@ -220,8 +226,8 @@ namespace boost {
|
||||
BOOST_FUNCTION_PARMS)
|
||||
|
||||
{
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(&function_obj_ptr.data);
|
||||
MemberPtr* f =
|
||||
reinterpret_cast<MemberPtr*>(function_obj_ptr.data);
|
||||
BOOST_FUNCTION_RETURN(boost::mem_fn(*f)(BOOST_FUNCTION_ARGS));
|
||||
}
|
||||
};
|
||||
@ -316,7 +322,7 @@ namespace boost {
|
||||
|
||||
/* Given the tag returned by get_function_tag, retrieve the
|
||||
actual invoker that will be used for the given function
|
||||
object.
|
||||
object.
|
||||
|
||||
Each specialization contains an "apply" nested class template
|
||||
that accepts the function object, return type, function
|
||||
@ -507,21 +513,21 @@ namespace boost {
|
||||
private:
|
||||
// Function pointers
|
||||
template<typename FunctionPtr>
|
||||
bool
|
||||
bool
|
||||
assign_to(FunctionPtr f, function_buffer& functor, function_ptr_tag) const
|
||||
{
|
||||
this->clear(functor);
|
||||
if (f) {
|
||||
// should be a reinterpret cast, but some compilers insist
|
||||
// on giving cv-qualifiers to free functions
|
||||
functor.func_ptr = reinterpret_cast<void (*)()>(f);
|
||||
functor.members.func_ptr = reinterpret_cast<void (*)()>(f);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
template<typename FunctionPtr,typename Allocator>
|
||||
bool
|
||||
bool
|
||||
assign_to_a(FunctionPtr f, function_buffer& functor, Allocator, function_ptr_tag) const
|
||||
{
|
||||
return assign_to(f,functor,function_ptr_tag());
|
||||
@ -560,13 +566,13 @@ namespace boost {
|
||||
// Function objects
|
||||
// Assign to a function object using the small object optimization
|
||||
template<typename FunctionObj>
|
||||
void
|
||||
void
|
||||
assign_functor(FunctionObj f, function_buffer& functor, mpl::true_) const
|
||||
{
|
||||
new (reinterpret_cast<void*>(&functor.data)) FunctionObj(f);
|
||||
new (reinterpret_cast<void*>(functor.data)) FunctionObj(f);
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
void
|
||||
void
|
||||
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, mpl::true_) const
|
||||
{
|
||||
assign_functor(f,functor,mpl::true_());
|
||||
@ -574,13 +580,13 @@ namespace boost {
|
||||
|
||||
// Assign to a function object allocated on the heap.
|
||||
template<typename FunctionObj>
|
||||
void
|
||||
void
|
||||
assign_functor(FunctionObj f, function_buffer& functor, mpl::false_) const
|
||||
{
|
||||
functor.obj_ptr = new FunctionObj(f);
|
||||
functor.members.obj_ptr = new FunctionObj(f);
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
void
|
||||
void
|
||||
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, mpl::false_) const
|
||||
{
|
||||
typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type;
|
||||
@ -591,15 +597,15 @@ namespace boost {
|
||||
wrapper_allocator_pointer_type copy = wrapper_allocator.allocate(1);
|
||||
wrapper_allocator.construct(copy, functor_wrapper_type(f,a));
|
||||
functor_wrapper_type* new_f = static_cast<functor_wrapper_type*>(copy);
|
||||
functor.obj_ptr = new_f;
|
||||
functor.members.obj_ptr = new_f;
|
||||
}
|
||||
|
||||
template<typename FunctionObj>
|
||||
bool
|
||||
bool
|
||||
assign_to(FunctionObj f, function_buffer& functor, function_obj_tag) const
|
||||
{
|
||||
if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
|
||||
assign_functor(f, functor,
|
||||
assign_functor(f, functor,
|
||||
mpl::bool_<(function_allows_small_object_optimization<FunctionObj>::value)>());
|
||||
return true;
|
||||
} else {
|
||||
@ -607,7 +613,7 @@ namespace boost {
|
||||
}
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
bool
|
||||
bool
|
||||
assign_to_a(FunctionObj f, function_buffer& functor, Allocator a, function_obj_tag) const
|
||||
{
|
||||
if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
|
||||
@ -621,18 +627,18 @@ namespace boost {
|
||||
|
||||
// Reference to a function object
|
||||
template<typename FunctionObj>
|
||||
bool
|
||||
assign_to(const reference_wrapper<FunctionObj>& f,
|
||||
bool
|
||||
assign_to(const reference_wrapper<FunctionObj>& f,
|
||||
function_buffer& functor, function_obj_ref_tag) const
|
||||
{
|
||||
functor.obj_ref.obj_ptr = (void *)(f.get_pointer());
|
||||
functor.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
|
||||
functor.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
|
||||
functor.members.obj_ref.obj_ptr = (void *)(f.get_pointer());
|
||||
functor.members.obj_ref.is_const_qualified = is_const<FunctionObj>::value;
|
||||
functor.members.obj_ref.is_volatile_qualified = is_volatile<FunctionObj>::value;
|
||||
return true;
|
||||
}
|
||||
template<typename FunctionObj,typename Allocator>
|
||||
bool
|
||||
assign_to_a(const reference_wrapper<FunctionObj>& f,
|
||||
bool
|
||||
assign_to_a(const reference_wrapper<FunctionObj>& f,
|
||||
function_buffer& functor, Allocator, function_obj_ref_tag) const
|
||||
{
|
||||
return assign_to(f,functor,function_obj_ref_tag());
|
||||
@ -650,17 +656,6 @@ namespace boost {
|
||||
BOOST_FUNCTION_TEMPLATE_PARMS
|
||||
>
|
||||
class BOOST_FUNCTION_FUNCTION : public function_base
|
||||
|
||||
#if BOOST_FUNCTION_NUM_ARGS == 1
|
||||
|
||||
, public std::unary_function<T0,R>
|
||||
|
||||
#elif BOOST_FUNCTION_NUM_ARGS == 2
|
||||
|
||||
, public std::binary_function<T0,T1,R>
|
||||
|
||||
#endif
|
||||
|
||||
{
|
||||
public:
|
||||
#ifndef BOOST_NO_VOID_RETURNS
|
||||
@ -711,9 +706,8 @@ namespace boost {
|
||||
template<typename Functor>
|
||||
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
,typename enable_if_c<
|
||||
(boost::type_traits::ice_not<
|
||||
(is_integral<Functor>::value)>::value),
|
||||
,typename boost::enable_if_c<
|
||||
!(is_integral<Functor>::value),
|
||||
int>::type = 0
|
||||
#endif // BOOST_NO_SFINAE
|
||||
) :
|
||||
@ -724,9 +718,8 @@ namespace boost {
|
||||
template<typename Functor,typename Allocator>
|
||||
BOOST_FUNCTION_FUNCTION(Functor BOOST_FUNCTION_TARGET_FIX(const &) f, Allocator a
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
,typename enable_if_c<
|
||||
(boost::type_traits::ice_not<
|
||||
(is_integral<Functor>::value)>::value),
|
||||
,typename boost::enable_if_c<
|
||||
!(is_integral<Functor>::value),
|
||||
int>::type = 0
|
||||
#endif // BOOST_NO_SFINAE
|
||||
) :
|
||||
@ -748,14 +741,14 @@ namespace boost {
|
||||
{
|
||||
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(); }
|
||||
|
||||
result_type operator()(BOOST_FUNCTION_PARMS) const
|
||||
@ -774,9 +767,8 @@ namespace boost {
|
||||
// construct.
|
||||
template<typename Functor>
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
typename enable_if_c<
|
||||
(boost::type_traits::ice_not<
|
||||
(is_integral<Functor>::value)>::value),
|
||||
typename boost::enable_if_c<
|
||||
!(is_integral<Functor>::value),
|
||||
BOOST_FUNCTION_FUNCTION&>::type
|
||||
#else
|
||||
BOOST_FUNCTION_FUNCTION&
|
||||
@ -837,12 +829,11 @@ namespace boost {
|
||||
BOOST_CATCH_END
|
||||
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;
|
||||
|
||||
@ -914,49 +905,15 @@ namespace boost {
|
||||
template<typename Functor>
|
||||
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 detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
||||
typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||
typedef typename get_invoker::
|
||||
template apply<Functor, R BOOST_FUNCTION_COMMA
|
||||
template apply<Functor, R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS>
|
||||
handler_type;
|
||||
|
||||
typedef typename handler_type::invoker_type invoker_type;
|
||||
typedef typename handler_type::manager_type manager_type;
|
||||
|
||||
// Note: it is extremely important that this initialization use
|
||||
// static initialization. Otherwise, we will have a race
|
||||
// condition here in multi-threaded code. See
|
||||
// http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
|
||||
static const vtable_type stored_vtable =
|
||||
{ { &manager_type::manage }, &invoker_type::invoke };
|
||||
|
||||
if (stored_vtable.assign_to(f, functor)) {
|
||||
std::size_t value = reinterpret_cast<std::size_t>(&stored_vtable.base);
|
||||
if (boost::has_trivial_copy_constructor<Functor>::value &&
|
||||
boost::has_trivial_destructor<Functor>::value &&
|
||||
detail::function::function_allows_small_object_optimization<Functor>::value)
|
||||
value |= static_cast<size_t>(0x01);
|
||||
vtable = reinterpret_cast<detail::function::vtable_base *>(value);
|
||||
} else
|
||||
vtable = 0;
|
||||
}
|
||||
|
||||
template<typename Functor,typename Allocator>
|
||||
void assign_to_a(Functor f,Allocator a)
|
||||
{
|
||||
using detail::function::vtable_base;
|
||||
|
||||
typedef typename detail::function::get_function_tag<Functor>::type tag;
|
||||
typedef detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||
typedef typename get_invoker::
|
||||
template apply_a<Functor, R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS,
|
||||
Allocator>
|
||||
handler_type;
|
||||
|
||||
typedef typename handler_type::invoker_type invoker_type;
|
||||
typedef typename handler_type::manager_type manager_type;
|
||||
|
||||
@ -967,22 +924,58 @@ namespace boost {
|
||||
static const vtable_type stored_vtable =
|
||||
{ { &manager_type::manage }, &invoker_type::invoke };
|
||||
|
||||
if (stored_vtable.assign_to_a(f, functor, a)) {
|
||||
if (stored_vtable.assign_to(f, functor)) {
|
||||
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 &&
|
||||
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);
|
||||
vtable = reinterpret_cast<detail::function::vtable_base *>(value);
|
||||
} else
|
||||
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
||||
} else
|
||||
vtable = 0;
|
||||
}
|
||||
|
||||
// Moves the value from the specified argument to *this. If the argument
|
||||
// has its function object allocated on the heap, move_assign will pass
|
||||
// its buffer to *this, and set the argument's buffer pointer to NULL.
|
||||
void move_assign(BOOST_FUNCTION_FUNCTION& f)
|
||||
{
|
||||
template<typename Functor,typename Allocator>
|
||||
void assign_to_a(Functor f,Allocator a)
|
||||
{
|
||||
using boost::detail::function::vtable_base;
|
||||
|
||||
typedef typename boost::detail::function::get_function_tag<Functor>::type tag;
|
||||
typedef boost::detail::function::BOOST_FUNCTION_GET_INVOKER<tag> get_invoker;
|
||||
typedef typename get_invoker::
|
||||
template apply_a<Functor, R BOOST_FUNCTION_COMMA
|
||||
BOOST_FUNCTION_TEMPLATE_ARGS,
|
||||
Allocator>
|
||||
handler_type;
|
||||
|
||||
typedef typename handler_type::invoker_type invoker_type;
|
||||
typedef typename handler_type::manager_type manager_type;
|
||||
|
||||
// Note: it is extremely important that this initialization use
|
||||
// static initialization. Otherwise, we will have a race
|
||||
// condition here in multi-threaded code. See
|
||||
// http://thread.gmane.org/gmane.comp.lib.boost.devel/164902/.
|
||||
static const vtable_type stored_vtable =
|
||||
{ { &manager_type::manage }, &invoker_type::invoke };
|
||||
|
||||
if (stored_vtable.assign_to_a(f, functor, a)) {
|
||||
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 &&
|
||||
boost::has_trivial_destructor<Functor>::value &&
|
||||
boost::detail::function::function_allows_small_object_optimization<Functor>::value)
|
||||
value |= static_cast<std::size_t>(0x01);
|
||||
vtable = reinterpret_cast<boost::detail::function::vtable_base *>(value);
|
||||
} else
|
||||
vtable = 0;
|
||||
}
|
||||
|
||||
// Moves the value from the specified argument to *this. If the argument
|
||||
// has its function object allocated on the heap, move_assign will pass
|
||||
// its buffer to *this, and set the argument's buffer pointer to NULL.
|
||||
void move_assign(BOOST_FUNCTION_FUNCTION& f)
|
||||
{
|
||||
if (&f == this)
|
||||
return;
|
||||
|
||||
@ -1060,9 +1053,8 @@ public:
|
||||
template<typename Functor>
|
||||
function(Functor f
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
,typename enable_if_c<
|
||||
(boost::type_traits::ice_not<
|
||||
(is_integral<Functor>::value)>::value),
|
||||
,typename boost::enable_if_c<
|
||||
!(is_integral<Functor>::value),
|
||||
int>::type = 0
|
||||
#endif
|
||||
) :
|
||||
@ -1072,9 +1064,8 @@ public:
|
||||
template<typename Functor,typename Allocator>
|
||||
function(Functor f, Allocator a
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
,typename enable_if_c<
|
||||
(boost::type_traits::ice_not<
|
||||
(is_integral<Functor>::value)>::value),
|
||||
,typename boost::enable_if_c<
|
||||
!(is_integral<Functor>::value),
|
||||
int>::type = 0
|
||||
#endif
|
||||
) :
|
||||
@ -1095,7 +1086,7 @@ public:
|
||||
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(f).swap(*this);
|
||||
@ -1108,13 +1099,12 @@ public:
|
||||
self_type(static_cast<self_type&&>(f)).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
template<typename Functor>
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
typename enable_if_c<
|
||||
(boost::type_traits::ice_not<
|
||||
(is_integral<Functor>::value)>::value),
|
||||
typename boost::enable_if_c<
|
||||
!(is_integral<Functor>::value),
|
||||
self_type&>::type
|
||||
#else
|
||||
self_type&
|
||||
@ -1138,14 +1128,14 @@ public:
|
||||
self_type(f).swap(*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
|
||||
#endif
|
||||
};
|
||||
|
||||
#undef BOOST_FUNCTION_PARTIAL_SPEC
|
||||
@ -1174,6 +1164,9 @@ public:
|
||||
#undef BOOST_FUNCTION_TEMPLATE_ARGS
|
||||
#undef BOOST_FUNCTION_PARMS
|
||||
#undef BOOST_FUNCTION_PARM
|
||||
#ifdef BOOST_FUNCTION_ARG
|
||||
# undef BOOST_FUNCTION_ARG
|
||||
#endif
|
||||
#undef BOOST_FUNCTION_ARGS
|
||||
#undef BOOST_FUNCTION_ARG_TYPE
|
||||
#undef BOOST_FUNCTION_ARG_TYPES
|
||||
@ -1182,4 +1175,4 @@ public:
|
||||
|
||||
#if defined(BOOST_MSVC)
|
||||
# pragma warning( pop )
|
||||
#endif
|
||||
#endif
|
||||
|
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>"
|
||||
]
|
||||
}
|
@ -21,6 +21,8 @@ import testing ;
|
||||
:
|
||||
[ run libs/function/test/function_test.cpp : : : : lib_function_test ]
|
||||
|
||||
[ run libs/function/test/function_test.cpp : : : <rtti>off : lib_function_test_no_rtti ]
|
||||
|
||||
[ run libs/function/test/function_n_test.cpp : : : : ]
|
||||
|
||||
[ run libs/function/test/allocator_test.cpp ../../../libs/test/build//boost_test_exec_monitor : : : : ]
|
||||
@ -61,7 +63,11 @@ import testing ;
|
||||
|
||||
[ run libs/function/test/nothrow_swap.cpp : : : : ]
|
||||
|
||||
[ run libs/function/test/rvalues_test.cpp : : : : ]
|
||||
|
||||
[ compile libs/function/test/function_typeof_test.cpp ]
|
||||
|
||||
[ run libs/function/test/result_arg_types_test.cpp ]
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -14,24 +14,32 @@
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
|
||||
struct Y {
|
||||
Y(int y = 0) : y_(y) {}
|
||||
bool operator==(const Y& rhs) { return y_ == rhs.y_; }
|
||||
private:
|
||||
int y_;
|
||||
};
|
||||
|
||||
struct X {
|
||||
int foo(int);
|
||||
std::ostream& foo2(std::ostream&) const;
|
||||
Y& foo2(Y&) const;
|
||||
};
|
||||
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()
|
||||
{
|
||||
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;
|
||||
f2 = &X::foo2;
|
||||
|
||||
X x;
|
||||
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();
|
||||
}
|
||||
|
@ -14,24 +14,32 @@
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
|
||||
struct Y {
|
||||
Y(int y = 0) : y_(y) {}
|
||||
bool operator==(const Y& rhs) { return y_ == rhs.y_; }
|
||||
private:
|
||||
int y_;
|
||||
};
|
||||
|
||||
struct X {
|
||||
int foo(int);
|
||||
std::ostream& foo2(std::ostream&) const;
|
||||
Y& foo2(Y&) const;
|
||||
};
|
||||
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()
|
||||
{
|
||||
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;
|
||||
f2 = &X::foo2;
|
||||
|
||||
X x;
|
||||
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();
|
||||
}
|
||||
|
40
test/result_arg_types_test.cpp
Normal file
40
test/result_arg_types_test.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// Boost.Function library
|
||||
|
||||
// Copyright 2016 Peter Dimov
|
||||
|
||||
// Use, modification and distribution is subject to
|
||||
// the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/core/is_same.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::function<X(Y)> F1;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<F1::result_type, X> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<F1::argument_type, Y> ));
|
||||
|
||||
typedef boost::function<X(Y, Z)> F2;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<F2::result_type, X> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<F2::first_argument_type, Y> ));
|
||||
BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<F2::second_argument_type, Z> ));
|
||||
|
||||
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;
|
||||
}
|
@ -20,11 +20,12 @@ int X::foo(int x) { return -x; }
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef BOOST_NO_CXX98_BINDERS
|
||||
boost::function<int (int)> f;
|
||||
X x;
|
||||
f = std::bind1st(
|
||||
std::mem_fun(&X::foo), &x);
|
||||
f(5); // Call x.foo(5)
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -20,11 +20,12 @@ int X::foo(int x) { return -x; }
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef BOOST_NO_CXX98_BINDERS
|
||||
boost::function1<int, int> f;
|
||||
X x;
|
||||
f = std::bind1st(
|
||||
std::mem_fun(&X::foo), &x);
|
||||
f(5); // Call x.foo(5)
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user