Compare commits

..

13 Commits

Author SHA1 Message Date
1204b7d200 Add missing argN_type typedefs. Fixes #51. 2024-06-05 16:48:43 +03:00
a39d5404d6 Add result_arg_n_types_test. Refs #51. 2024-06-05 16:36:38 +03:00
bd181fdf89 Update .drone.jsonnet 2024-05-11 22:39:29 +03:00
9788bb6cea Update ci.yml 2024-05-11 22:22:56 +03:00
694b253086 Use std::is_trivially_copyable instead of is_trivially_copy_constructible + is_trivially_destructible 2024-05-11 22:14:19 +03:00
35f0c2a681 GCC 4.x doesn't have std::is_trivially_copy_constructible 2024-05-11 21:51:45 +03:00
4f89a283fd Fix GCC 4.8 in .drone.jsonnet 2024-05-11 21:38:42 +03:00
38a2ab7646 Remove dependency on Boost.TypeTraits 2024-05-11 21:26:24 +03:00
28b88d07bb Fix indentation; remove obsolete comment 2024-02-06 08:57:58 +02:00
e51f941dd4 Merge branch 'patch-2' of https://github.com/BrianWeed/function into feature/pr-48 2024-02-06 08:48:34 +02:00
483504c615 Merge pull request #49 from BrianWeed/patch-1
Performance improvement
2024-02-06 08:47:02 +02:00
7350f9b354 Performance Improvement
Move functors where possible to reduce the number of copies (Lambdas with expensive-to-copy captures can be a bottleneck when copied)
2024-02-04 14:28:10 -05:00
3b48732773 Performance improvement
Move functors where possible to reduce the number of copies (Lambdas with expensive-to-copy captures can be a bottleneck when copied)
2024-02-04 14:25:58 -05:00
6 changed files with 375 additions and 111 deletions

View File

@ -106,7 +106,7 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
linux_pipeline(
"Linux 16.04 GCC 4.8 32/64",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11', ADDRMD: '32,64' },
{ TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '11', ADDRMD: '32,64' },
"g++-4.8-multilib",
),
@ -150,16 +150,23 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
),
linux_pipeline(
"Linux 20.04 GCC 9* ARM64",
"Linux 20.04 GCC 9* ARM64 ASAN",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' },
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' } + asan,
arch="arm64",
),
linux_pipeline(
"Linux 20.04 GCC 9* S390x",
"Linux 20.04 GCC 9* ARM64 UBSAN",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' },
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' } + ubsan,
arch="arm64",
),
linux_pipeline(
"Linux 20.04 GCC 9* S390x UBSAN",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' } + ubsan,
arch="s390x",
),
@ -184,31 +191,24 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
),
linux_pipeline(
"Linux 23.04 GCC 13 32 ASAN",
"Linux 23.04 GCC 13 32/64 ASAN",
"cppalliance/droneubuntu2304:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + asan,
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32,64' } + asan,
"g++-13-multilib",
),
linux_pipeline(
"Linux 23.04 GCC 13 64 ASAN",
"Linux 23.04 GCC 13 32/64 UBSAN",
"cppalliance/droneubuntu2304:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + asan,
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32,64' } + ubsan,
"g++-13-multilib",
),
linux_pipeline(
"Linux 23.04 GCC 13 32 UBSAN",
"cppalliance/droneubuntu2304:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + ubsan,
"g++-13-multilib",
),
linux_pipeline(
"Linux 23.04 GCC 13 64 UBSAN",
"cppalliance/droneubuntu2304:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + ubsan,
"g++-13-multilib",
"Linux 24.04 GCC 14 32/64",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '32,64' },
"g++-14-multilib",
),
linux_pipeline(
@ -351,6 +351,20 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
"clang-17",
),
linux_pipeline(
"Linux 24.04 Clang 18 UBSAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + ubsan,
"clang-18",
),
linux_pipeline(
"Linux 24.04 Clang 18 ASAN",
"cppalliance/droneubuntu2404:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + asan,
"clang-18",
),
macos_pipeline(
"MacOS 10.15 Xcode 12.2 UBSAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,2a' } + ubsan,

View File

@ -83,6 +83,12 @@ jobs:
os: ubuntu-latest
install: g++-13-multilib
address-model: 32,64
- toolset: gcc-14
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.04
os: ubuntu-latest
install: g++-14-multilib
address-model: 32,64
- toolset: clang
compiler: clang++-3.9
cxxstd: "11,14"
@ -163,6 +169,12 @@ jobs:
container: ubuntu:23.10
os: ubuntu-latest
install: clang-17
- toolset: clang
compiler: clang++-18
cxxstd: "11,14,17,20,2b"
container: ubuntu:24.04
os: ubuntu-latest
install: clang-18
- toolset: clang
cxxstd: "11,14,17,2a"
os: macos-11
@ -172,6 +184,9 @@ jobs:
- toolset: clang
cxxstd: "11,14,17,20,2b"
os: macos-13
- toolset: clang
cxxstd: "11,14,17,20,2b"
os: macos-14
runs-on: ${{matrix.os}}
container: ${{matrix.container}}

View File

@ -15,17 +15,6 @@
#include <boost/function_equal.hpp>
#include <boost/core/typeinfo.hpp>
#include <boost/core/ref.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/conditional.hpp>
#include <boost/type_traits/alignment_of.hpp>
#include <boost/type_traits/enable_if.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
@ -33,6 +22,7 @@
#include <string>
#include <memory>
#include <new>
#include <type_traits>
#if defined(BOOST_MSVC)
# pragma warning( push )
@ -43,10 +33,8 @@
// retained because used in a test
#define BOOST_FUNCTION_TARGET_FIX(x)
# define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
typename ::boost::enable_if_< \
!(::boost::is_integral<Functor>::value), \
Type>::type
#define BOOST_FUNCTION_ENABLE_IF_NOT_INTEGRAL(Functor,Type) \
typename std::enable_if< !std::is_integral<Functor>::value, Type>::type
namespace boost {
namespace detail {
@ -131,15 +119,15 @@ namespace boost {
template<typename F>
class get_function_tag
{
typedef typename conditional<(is_pointer<F>::value),
typedef typename std::conditional<std::is_pointer<F>::value,
function_ptr_tag,
function_obj_tag>::type ptr_or_obj_tag;
typedef typename conditional<(is_member_pointer<F>::value),
typedef typename std::conditional<std::is_member_pointer<F>::value,
member_ptr_tag,
ptr_or_obj_tag>::type ptr_or_obj_or_mem_tag;
typedef typename conditional<(is_reference_wrapper<F>::value),
typedef typename std::conditional<is_reference_wrapper<F>::value,
function_obj_ref_tag,
ptr_or_obj_or_mem_tag>::type or_ref_tag;
@ -204,8 +192,8 @@ namespace boost {
BOOST_STATIC_CONSTANT
(bool,
value = ((sizeof(F) <= sizeof(function_buffer) &&
(alignment_of<function_buffer>::value
% alignment_of<F>::value == 0))));
(std::alignment_of<function_buffer>::value
% std::alignment_of<F>::value == 0))));
};
template <typename F,typename A>
@ -262,16 +250,15 @@ namespace boost {
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) {
if (op == clone_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);
if (op == move_functor_tag) {
} else if (op == move_functor_tag) {
functor_type* f = reinterpret_cast<functor_type*>(in_buffer.data);
(void)f; // suppress warning about the value of f not being used (MSVC)
new (reinterpret_cast<void*>(out_buffer.data)) functor_type(std::move(*f));
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);
@ -307,7 +294,7 @@ namespace boost {
// Function objects that fit in the small-object buffer.
static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, true_type)
functor_manager_operation_type op, std::true_type)
{
functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op);
}
@ -315,7 +302,7 @@ namespace boost {
// Function objects that require heap allocation
static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, false_type)
functor_manager_operation_type op, std::false_type)
{
if (op == clone_functor_tag) {
// Clone the functor
@ -356,7 +343,7 @@ namespace boost {
functor_manager_operation_type op, function_obj_tag)
{
manager(in_buffer, out_buffer, op,
integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>());
std::integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>());
}
// For member pointers, we use the small-object optimization buffer.
@ -364,7 +351,7 @@ namespace boost {
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, member_ptr_tag)
{
manager(in_buffer, out_buffer, op, true_type());
manager(in_buffer, out_buffer, op, std::true_type());
}
public:
@ -402,7 +389,7 @@ namespace boost {
// Function objects that fit in the small-object buffer.
static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, true_type)
functor_manager_operation_type op, std::true_type)
{
functor_manager_common<Functor>::manage_small(in_buffer,out_buffer,op);
}
@ -410,7 +397,7 @@ namespace boost {
// Function objects that require heap allocation
static inline void
manager(const function_buffer& in_buffer, function_buffer& out_buffer,
functor_manager_operation_type op, false_type)
functor_manager_operation_type op, std::false_type)
{
typedef functor_wrapper<Functor,Allocator> functor_wrapper_type;
@ -461,7 +448,7 @@ namespace boost {
functor_manager_operation_type op, function_obj_tag)
{
manager(in_buffer, out_buffer, op,
integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>());
std::integral_constant<bool, (function_allows_small_object_optimization<functor_type>::value)>());
}
public:
@ -530,8 +517,8 @@ public:
detail::function::function_buffer type_result;
type_result.members.type.type = &BOOST_CORE_TYPEID(Functor);
type_result.members.type.const_qualified = is_const<Functor>::value;
type_result.members.type.volatile_qualified = is_volatile<Functor>::value;
type_result.members.type.const_qualified = std::is_const<Functor>::value;
type_result.members.type.volatile_qualified = std::is_volatile<Functor>::value;
get_vtable()->manager(functor, type_result,
detail::function::check_functor_type_tag);
return static_cast<Functor*>(type_result.members.obj_ptr);
@ -545,7 +532,7 @@ public:
detail::function::function_buffer type_result;
type_result.members.type.type = &BOOST_CORE_TYPEID(Functor);
type_result.members.type.const_qualified = true;
type_result.members.type.volatile_qualified = is_volatile<Functor>::value;
type_result.members.type.volatile_qualified = std::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
@ -554,8 +541,8 @@ public:
}
template<typename F>
typename boost::enable_if_< !boost::is_function<F>::value, bool >::type
contains(const F& f) const
typename std::enable_if< !std::is_function<F>::value, bool >::type
contains(const F& f) const
{
if (const F* fp = this->template target<F>())
{
@ -566,8 +553,8 @@ public:
}
template<typename Fn>
typename boost::enable_if_< boost::is_function<Fn>::value, bool >::type
contains(Fn& f) const
typename std::enable_if< std::is_function<Fn>::value, bool >::type
contains(Fn& f) const
{
typedef Fn* F;
if (const F* fp = this->template target<F>())

View File

@ -15,11 +15,10 @@
#include <boost/core/no_exceptions_support.hpp>
#include <boost/mem_fn.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/config.hpp>
#include <algorithm>
#include <cassert>
#include <type_traits>
#if defined(BOOST_MSVC)
# pragma warning( push )
@ -180,7 +179,7 @@ namespace boost {
>
struct get_function_invoker
{
typedef typename conditional<(is_void<R>::value),
typedef typename std::conditional<std::is_void<R>::value,
void_function_invoker<
FunctionPtr,
R,
@ -201,7 +200,7 @@ namespace boost {
>
struct get_function_obj_invoker
{
typedef typename conditional<(is_void<R>::value),
typedef typename std::conditional<std::is_void<R>::value,
void_function_obj_invoker<
FunctionObj,
R,
@ -222,7 +221,7 @@ namespace boost {
>
struct get_function_ref_invoker
{
typedef typename conditional<(is_void<R>::value),
typedef typename std::conditional<std::is_void<R>::value,
void_function_ref_invoker<
FunctionObj,
R,
@ -244,7 +243,7 @@ namespace boost {
>
struct get_member_invoker
{
typedef typename conditional<(is_void<R>::value),
typedef typename std::conditional<std::is_void<R>::value,
void_member_invoker<
MemberPtr,
R,
@ -423,13 +422,13 @@ namespace boost {
bool assign_to(F f, function_buffer& functor) const
{
typedef typename get_function_tag<F>::type tag;
return assign_to(f, functor, tag());
return assign_to(std::move(f), functor, tag());
}
template<typename F,typename Allocator>
bool assign_to_a(F f, function_buffer& functor, Allocator a) const
{
typedef typename get_function_tag<F>::type tag;
return assign_to_a(f, functor, a, tag());
return assign_to_a(std::move(f), functor, a, tag());
}
void clear(function_buffer& functor) const
@ -454,8 +453,6 @@ namespace boost {
{
this->clear(functor);
if (f) {
// should be a reinterpret cast, but some compilers insist
// on giving cv-qualifiers to free functions
functor.members.func_ptr = reinterpret_cast<void (*)()>(f);
return true;
} else {
@ -466,7 +463,7 @@ namespace boost {
bool
assign_to_a(FunctionPtr f, function_buffer& functor, Allocator, function_ptr_tag) const
{
return assign_to(f,functor,function_ptr_tag());
return assign_to(std::move(f),functor,function_ptr_tag());
}
// Member pointers
@ -501,27 +498,27 @@ namespace boost {
// Assign to a function object using the small object optimization
template<typename FunctionObj>
void
assign_functor(FunctionObj f, function_buffer& functor, true_type) const
assign_functor(FunctionObj f, function_buffer& functor, std::true_type) const
{
new (reinterpret_cast<void*>(functor.data)) FunctionObj(f);
new (reinterpret_cast<void*>(functor.data)) FunctionObj(std::move(f));
}
template<typename FunctionObj,typename Allocator>
void
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, true_type) const
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator, std::true_type) const
{
assign_functor(f,functor,true_type());
assign_functor(std::move(f),functor,std::true_type());
}
// Assign to a function object allocated on the heap.
template<typename FunctionObj>
void
assign_functor(FunctionObj f, function_buffer& functor, false_type) const
assign_functor(FunctionObj f, function_buffer& functor, std::false_type) const
{
functor.members.obj_ptr = new FunctionObj(f);
functor.members.obj_ptr = new FunctionObj(std::move(f));
}
template<typename FunctionObj,typename Allocator>
void
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, false_type) const
assign_functor_a(FunctionObj f, function_buffer& functor, Allocator a, std::false_type) const
{
typedef functor_wrapper<FunctionObj,Allocator> functor_wrapper_type;
@ -541,8 +538,8 @@ namespace boost {
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,
integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
assign_functor(std::move(f), functor,
std::integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
return true;
} else {
return false;
@ -553,8 +550,8 @@ namespace boost {
assign_to_a(FunctionObj f, function_buffer& functor, Allocator a, function_obj_tag) const
{
if (!boost::detail::function::has_empty_target(boost::addressof(f))) {
assign_functor_a(f, functor, a,
integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
assign_functor_a(std::move(f), functor, a,
std::integral_constant<bool, (function_allows_small_object_optimization<FunctionObj>::value)>());
return true;
} else {
return false;
@ -568,8 +565,8 @@ namespace boost {
function_buffer& functor, function_obj_ref_tag) const
{
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;
functor.members.obj_ref.is_const_qualified = std::is_const<FunctionObj>::value;
functor.members.obj_ref.is_volatile_qualified = std::is_volatile<FunctionObj>::value;
return true;
}
template<typename FunctionObj,typename Allocator>
@ -589,19 +586,125 @@ namespace boost {
struct variadic_function_base
{};
template <typename T>
struct variadic_function_base<T>
template <typename T1>
struct variadic_function_base<T1>
{
typedef T argument_type;
typedef T1 argument_type;
typedef T1 arg1_type;
};
template <typename T0, typename T1>
struct variadic_function_base<T0, T1>
template <typename T1, typename T2>
struct variadic_function_base<T1, T2>
{
typedef T0 first_argument_type;
typedef T1 second_argument_type;
typedef T1 first_argument_type;
typedef T2 second_argument_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
};
template <typename T1, typename T2, typename T3>
struct variadic_function_base<T1, T2, T3>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
};
template <typename T1, typename T2, typename T3, typename T4>
struct variadic_function_base<T1, T2, T3, T4>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
};
template <typename T1, typename T2, typename T3, typename T4, typename T5>
struct variadic_function_base<T1, T2, T3, T4, T5>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct variadic_function_base<T1, T2, T3, T4, T5, T6>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
typedef T6 arg6_type;
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct variadic_function_base<T1, T2, T3, T4, T5, T6, T7>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
typedef T6 arg6_type;
typedef T7 arg7_type;
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct variadic_function_base<T1, T2, T3, T4, T5, T6, T7, T8>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
typedef T6 arg6_type;
typedef T7 arg7_type;
typedef T8 arg8_type;
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct variadic_function_base<T1, T2, T3, T4, T5, T6, T7, T8, T9>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
typedef T6 arg6_type;
typedef T7 arg7_type;
typedef T8 arg8_type;
typedef T9 arg9_type;
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
struct variadic_function_base<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>
{
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
typedef T6 arg6_type;
typedef T7 arg7_type;
typedef T8 arg8_type;
typedef T9 arg9_type;
typedef T10 arg10_type;
};
#if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000
template<class T> struct is_trivially_copyable: std::integral_constant<bool,
__has_trivial_copy(T) && __has_trivial_assign(T) && __has_trivial_destructor(T)> {};
#else
using std::is_trivially_copyable;
#endif
} // end namespace function
} // end namespace detail
@ -645,23 +748,23 @@ namespace boost {
// one with a default parameter.
template<typename Functor>
function_n(Functor f
,typename boost::enable_if_<
!(is_integral<Functor>::value),
,typename std::enable_if<
!std::is_integral<Functor>::value,
int>::type = 0
) :
function_base()
{
this->assign_to(f);
this->assign_to(std::move(f));
}
template<typename Functor,typename Allocator>
function_n(Functor f, Allocator a
,typename boost::enable_if_<
!(is_integral<Functor>::value),
,typename std::enable_if<
!std::is_integral<Functor>::value,
int>::type = 0
) :
function_base()
{
this->assign_to_a(f,a);
this->assign_to_a(std::move(f),a);
}
function_n(clear_type*) : function_base() { }
@ -693,8 +796,8 @@ namespace boost {
// handle function_n as the type of the temporary to
// construct.
template<typename Functor>
typename boost::enable_if_<
!(is_integral<Functor>::value),
typename std::enable_if<
!std::is_integral<Functor>::value,
function_n&>::type
operator=(Functor f)
{
@ -834,11 +937,10 @@ namespace boost {
static const vtable_type stored_vtable =
{ { &manager_type::manage }, &invoker_type::invoke };
if (stored_vtable.assign_to(f, functor)) {
if (stored_vtable.assign_to(std::move(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 &&
if (boost::detail::function::is_trivially_copyable<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);
@ -868,11 +970,10 @@ 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_a(std::move(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 &&
if (boost::detail::function::is_trivially_copyable<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);
@ -976,20 +1077,20 @@ public:
template<typename Functor>
function(Functor f
,typename boost::enable_if_<
!(is_integral<Functor>::value),
,typename std::enable_if<
!std::is_integral<Functor>::value,
int>::type = 0
) :
base_type(f)
base_type(std::move(f))
{
}
template<typename Functor,typename Allocator>
function(Functor f, Allocator a
,typename boost::enable_if_<
!(is_integral<Functor>::value),
,typename std::enable_if<
!std::is_integral<Functor>::value,
int>::type = 0
) :
base_type(f,a)
base_type(std::move(f),a)
{
}
@ -1016,8 +1117,8 @@ public:
}
template<typename Functor>
typename boost::enable_if_<
!(is_integral<Functor>::value),
typename std::enable_if<
!std::is_integral<Functor>::value,
self_type&>::type
operator=(Functor f)
{

View File

@ -46,6 +46,7 @@ run rvalues_test.cpp ;
compile function_typeof_test.cpp
: <cxxstd>03:<build>no <cxxstd>98:<build>no <cxxstd>0x:<build>no ;
run result_arg_types_test.cpp ;
run result_arg_n_types_test.cpp ;
lib throw_bad_function_call : throw_bad_function_call.cpp : <link>shared:<define>THROW_BAD_FUNCTION_CALL_DYN_LINK=1 ;

View File

@ -0,0 +1,146 @@
// Copyright 2024 Peter Dimov
// Use, modification and distribution is subject to
// the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/function.hpp>
#include <boost/core/lightweight_test_trait.hpp>
struct R {};
struct A1 {};
struct A2 {};
struct A3 {};
struct A4 {};
struct A5 {};
struct A6 {};
struct A7 {};
struct A8 {};
struct A9 {};
struct A10 {};
int main()
{
{
typedef boost::function<R()> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
}
{
typedef boost::function<R(A1)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
}
{
typedef boost::function<R(A1, A2)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
}
{
typedef boost::function<R(A1, A2, A3)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
}
{
typedef boost::function<R(A1, A2, A3, A4)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
BOOST_TEST_TRAIT_SAME(F::arg4_type, A4);
}
{
typedef boost::function<R(A1, A2, A3, A4, A5)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
BOOST_TEST_TRAIT_SAME(F::arg4_type, A4);
BOOST_TEST_TRAIT_SAME(F::arg5_type, A5);
}
{
typedef boost::function<R(A1, A2, A3, A4, A5, A6)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
BOOST_TEST_TRAIT_SAME(F::arg4_type, A4);
BOOST_TEST_TRAIT_SAME(F::arg5_type, A5);
BOOST_TEST_TRAIT_SAME(F::arg6_type, A6);
}
{
typedef boost::function<R(A1, A2, A3, A4, A5, A6, A7)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
BOOST_TEST_TRAIT_SAME(F::arg4_type, A4);
BOOST_TEST_TRAIT_SAME(F::arg5_type, A5);
BOOST_TEST_TRAIT_SAME(F::arg6_type, A6);
BOOST_TEST_TRAIT_SAME(F::arg7_type, A7);
}
{
typedef boost::function<R(A1, A2, A3, A4, A5, A6, A7, A8)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
BOOST_TEST_TRAIT_SAME(F::arg4_type, A4);
BOOST_TEST_TRAIT_SAME(F::arg5_type, A5);
BOOST_TEST_TRAIT_SAME(F::arg6_type, A6);
BOOST_TEST_TRAIT_SAME(F::arg7_type, A7);
BOOST_TEST_TRAIT_SAME(F::arg8_type, A8);
}
{
typedef boost::function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
BOOST_TEST_TRAIT_SAME(F::arg4_type, A4);
BOOST_TEST_TRAIT_SAME(F::arg5_type, A5);
BOOST_TEST_TRAIT_SAME(F::arg6_type, A6);
BOOST_TEST_TRAIT_SAME(F::arg7_type, A7);
BOOST_TEST_TRAIT_SAME(F::arg8_type, A8);
BOOST_TEST_TRAIT_SAME(F::arg9_type, A9);
}
{
typedef boost::function<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> F;
BOOST_TEST_TRAIT_SAME(F::result_type, R);
BOOST_TEST_TRAIT_SAME(F::arg1_type, A1);
BOOST_TEST_TRAIT_SAME(F::arg2_type, A2);
BOOST_TEST_TRAIT_SAME(F::arg3_type, A3);
BOOST_TEST_TRAIT_SAME(F::arg4_type, A4);
BOOST_TEST_TRAIT_SAME(F::arg5_type, A5);
BOOST_TEST_TRAIT_SAME(F::arg6_type, A6);
BOOST_TEST_TRAIT_SAME(F::arg7_type, A7);
BOOST_TEST_TRAIT_SAME(F::arg8_type, A8);
BOOST_TEST_TRAIT_SAME(F::arg9_type, A9);
BOOST_TEST_TRAIT_SAME(F::arg10_type, A10);
}
return boost::report_errors();
}