整理
This commit is contained in:
365
include/boost/functional/factory.hpp
Normal file
365
include/boost/functional/factory.hpp
Normal file
@@ -0,0 +1,365 @@
|
||||
/*
|
||||
Copyright 2007 Tobias Schwinger
|
||||
|
||||
Copyright 2019 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_FUNCTIONAL_FACTORY_HPP
|
||||
#define BOOST_FUNCTIONAL_FACTORY_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/empty_value.hpp>
|
||||
#include <boost/core/pointer_traits.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#include <memory>
|
||||
#endif
|
||||
#include <new>
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
enum factory_alloc_propagation {
|
||||
factory_alloc_for_pointee_and_deleter,
|
||||
factory_passes_alloc_to_smart_pointer
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<factory_alloc_propagation>
|
||||
struct fc_tag { };
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class A, class T>
|
||||
struct fc_rebind {
|
||||
typedef typename std::allocator_traits<A>::template rebind_alloc<T> type;
|
||||
};
|
||||
|
||||
template<class A>
|
||||
struct fc_pointer {
|
||||
typedef typename std::allocator_traits<A>::pointer type;
|
||||
};
|
||||
#else
|
||||
template<class A, class T>
|
||||
struct fc_rebind {
|
||||
typedef typename A::template rebind<T>::other type;
|
||||
};
|
||||
|
||||
template<class A>
|
||||
struct fc_pointer {
|
||||
typedef typename A::pointer type;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR) && \
|
||||
!defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class A, class T>
|
||||
inline void
|
||||
fc_destroy(A& a, T* p)
|
||||
{
|
||||
std::allocator_traits<A>::destroy(a, p);
|
||||
}
|
||||
#else
|
||||
template<class A, class T>
|
||||
inline void
|
||||
fc_destroy(A&, T* p)
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
template<class A, class T, class... Args>
|
||||
inline void
|
||||
fc_construct(A& a, T* p, Args&&... args)
|
||||
{
|
||||
std::allocator_traits<A>::construct(a, p, std::forward<Args>(args)...);
|
||||
}
|
||||
#else
|
||||
template<class A, class T, class... Args>
|
||||
inline void
|
||||
fc_construct(A&, T* p, Args&&... args)
|
||||
{
|
||||
::new((void*)p) T(std::forward<Args>(args)...);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
template<class A>
|
||||
class fc_delete
|
||||
: boost::empty_value<A> {
|
||||
typedef boost::empty_value<A> base;
|
||||
|
||||
public:
|
||||
explicit fc_delete(const A& a) BOOST_NOEXCEPT
|
||||
: base(boost::empty_init_t(), a) { }
|
||||
|
||||
void operator()(typename fc_pointer<A>::type p) {
|
||||
boost::detail::fc_destroy(base::get(), boost::to_address(p));
|
||||
base::get().deallocate(p, 1);
|
||||
}
|
||||
};
|
||||
|
||||
template<class R, class A>
|
||||
class fc_allocate {
|
||||
public:
|
||||
explicit fc_allocate(const A& a)
|
||||
: a_(a)
|
||||
, p_(a_.allocate(1)) { }
|
||||
|
||||
~fc_allocate() {
|
||||
if (p_) {
|
||||
a_.deallocate(p_, 1);
|
||||
}
|
||||
}
|
||||
|
||||
A& state() BOOST_NOEXCEPT {
|
||||
return a_;
|
||||
}
|
||||
|
||||
typename A::value_type* get() const BOOST_NOEXCEPT {
|
||||
return boost::to_address(p_);
|
||||
}
|
||||
|
||||
R release(fc_tag<factory_alloc_for_pointee_and_deleter>) {
|
||||
return R(release(), fc_delete<A>(a_), a_);
|
||||
}
|
||||
|
||||
R release(fc_tag<factory_passes_alloc_to_smart_pointer>) {
|
||||
return R(release(), fc_delete<A>(a_));
|
||||
}
|
||||
|
||||
private:
|
||||
typedef typename fc_pointer<A>::type pointer;
|
||||
|
||||
pointer release() BOOST_NOEXCEPT {
|
||||
pointer p = p_;
|
||||
p_ = pointer();
|
||||
return p;
|
||||
}
|
||||
|
||||
fc_allocate(const fc_allocate&);
|
||||
fc_allocate& operator=(const fc_allocate&);
|
||||
|
||||
A a_;
|
||||
pointer p_;
|
||||
};
|
||||
|
||||
} /* detail */
|
||||
|
||||
template<class Pointer, class Allocator = void,
|
||||
factory_alloc_propagation Policy = factory_alloc_for_pointee_and_deleter>
|
||||
class factory;
|
||||
|
||||
template<class Pointer, factory_alloc_propagation Policy>
|
||||
class factory<Pointer, void, Policy> {
|
||||
public:
|
||||
typedef typename remove_cv<Pointer>::type result_type;
|
||||
|
||||
private:
|
||||
typedef typename pointer_traits<result_type>::element_type type;
|
||||
|
||||
public:
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class... Args>
|
||||
result_type operator()(Args&&... args) const {
|
||||
return result_type(new type(std::forward<Args>(args)...));
|
||||
}
|
||||
#else
|
||||
result_type operator()() const {
|
||||
return result_type(new type());
|
||||
}
|
||||
|
||||
template<class A0>
|
||||
result_type operator()(A0& a0) const {
|
||||
return result_type(new type(a0));
|
||||
}
|
||||
|
||||
template<class A0, class A1>
|
||||
result_type operator()(A0& a0, A1& a1) const {
|
||||
return result_type(new type(a0, a1));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2) const {
|
||||
return result_type(new type(a0, a1, a2));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3) const {
|
||||
return result_type(new type(a0, a1, a2, a3));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4) const {
|
||||
return result_type(new type(a0, a1, a2, a3, a4));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4,
|
||||
A5& a5) const {
|
||||
return result_type(new type(a0, a1, a2, a3, a4, a5));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6) const {
|
||||
return result_type(new type(a0, a1, a2, a3, a4, a5, a6));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7) const {
|
||||
return result_type(new type(a0, a1, a2, a3, a4, a5, a6, a7));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7, class A8>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7, A8& a8) const {
|
||||
return result_type(new type(a0, a1, a2, a3, a4, a5, a6, a7, a8));
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7, class A8, class A9>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7, A8& a8, A9& a9) const {
|
||||
return result_type(new type(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9));
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template<class Pointer, class Allocator, factory_alloc_propagation Policy>
|
||||
class factory
|
||||
: empty_value<typename detail::fc_rebind<Allocator,
|
||||
typename pointer_traits<typename
|
||||
remove_cv<Pointer>::type>::element_type>::type> {
|
||||
public:
|
||||
typedef typename remove_cv<Pointer>::type result_type;
|
||||
|
||||
private:
|
||||
typedef typename pointer_traits<result_type>::element_type type;
|
||||
typedef typename detail::fc_rebind<Allocator, type>::type allocator;
|
||||
typedef empty_value<allocator> base;
|
||||
|
||||
public:
|
||||
factory() BOOST_NOEXCEPT
|
||||
: base(empty_init_t()) { }
|
||||
|
||||
explicit factory(const Allocator& a) BOOST_NOEXCEPT
|
||||
: base(empty_init_t(), a) { }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class... Args>
|
||||
result_type operator()(Args&&... args) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
detail::fc_construct(s.state(), s.get(), std::forward<Args>(args)...);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
#else
|
||||
result_type operator()() const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type();
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0>
|
||||
result_type operator()(A0& a0) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1>
|
||||
result_type operator()(A0& a0, A1& a1) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2, a3);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2, a3, a4);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4,
|
||||
A5& a5) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2, a3, a4, a5);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2, a3, a4, a5, a6);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2, a3, a4, a5, a6, a7);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7, class A8>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7, A8& a8) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7, class A8, class A9>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7, A8& a8, A9& a9) const {
|
||||
detail::fc_allocate<result_type, allocator> s(base::get());
|
||||
::new((void*)s.get()) type(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
||||
return s.release(detail::fc_tag<Policy>());
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template<class Pointer, class Allocator, factory_alloc_propagation Policy>
|
||||
class factory<Pointer&, Allocator, Policy> { };
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
501
include/boost/functional/forward_adapter.hpp
Normal file
501
include/boost/functional/forward_adapter.hpp
Normal file
@@ -0,0 +1,501 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2007-2008 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are 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).
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUNCTIONAL_FORWARD_ADAPTER_HPP_INCLUDED
|
||||
# ifndef BOOST_PP_IS_ITERATING
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/config/workaround.hpp>
|
||||
|
||||
# include <boost/preprocessor/iteration/iterate.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
# include <boost/preprocessor/facilities/intercept.hpp>
|
||||
# include <boost/preprocessor/arithmetic/dec.hpp>
|
||||
|
||||
# include <boost/utility/result_of.hpp>
|
||||
|
||||
# ifndef BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY
|
||||
# define BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY 6
|
||||
# elif BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY < 3
|
||||
# undef BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY
|
||||
# define BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY 3
|
||||
# endif
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< typename Function, int Arity_Or_MinArity = -1, int MaxArity = -1 >
|
||||
class forward_adapter;
|
||||
|
||||
//----- ---- --- -- - - - -
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< class MostDerived, typename Function, typename FunctionConst,
|
||||
int Arity, int MinArity >
|
||||
struct forward_adapter_impl;
|
||||
|
||||
struct forward_adapter_result
|
||||
{
|
||||
template< typename Sig > struct apply;
|
||||
|
||||
// Utility metafunction for qualification adjustment on arguments
|
||||
template< typename T > struct q { typedef T const t; };
|
||||
template< typename T > struct q<T const> { typedef T const t; };
|
||||
template< typename T > struct q<T &> { typedef T t; };
|
||||
|
||||
// Utility metafunction to choose target function qualification
|
||||
template< typename T > struct c
|
||||
{ typedef typename T::target_function_t t; };
|
||||
template< typename T > struct c<T& >
|
||||
{ typedef typename T::target_function_t t; };
|
||||
template< typename T > struct c<T const >
|
||||
{ typedef typename T::target_function_const_t t; };
|
||||
template< typename T > struct c<T const&>
|
||||
{ typedef typename T::target_function_const_t t; };
|
||||
};
|
||||
}
|
||||
|
||||
# define BOOST_TMP_MACRO(f,fn,fc) \
|
||||
boost::detail::forward_adapter_impl< \
|
||||
forward_adapter<f,Arity_Or_MinArity,MaxArity>, fn, fc, \
|
||||
(MaxArity!=-1? MaxArity :Arity_Or_MinArity!=-1? Arity_Or_MinArity \
|
||||
:BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY), \
|
||||
(Arity_Or_MinArity!=-1? Arity_Or_MinArity : 0) >
|
||||
|
||||
template< typename Function, int Arity_Or_MinArity, int MaxArity >
|
||||
class forward_adapter
|
||||
: public BOOST_TMP_MACRO(Function,Function,Function const)
|
||||
, private Function
|
||||
{
|
||||
public:
|
||||
forward_adapter(Function const& f = Function())
|
||||
: Function(f)
|
||||
{ }
|
||||
|
||||
typedef Function target_function_t;
|
||||
typedef Function const target_function_const_t;
|
||||
|
||||
Function & target_function() { return *this; }
|
||||
Function const & target_function() const { return *this; }
|
||||
|
||||
template< typename Sig > struct result
|
||||
: detail::forward_adapter_result::template apply<Sig>
|
||||
{ };
|
||||
|
||||
using BOOST_TMP_MACRO(Function,Function, Function const)::operator();
|
||||
};
|
||||
template< typename Function, int Arity_Or_MinArity, int MaxArity >
|
||||
class forward_adapter< Function const, Arity_Or_MinArity, MaxArity >
|
||||
: public BOOST_TMP_MACRO(Function const, Function const, Function const)
|
||||
, private Function
|
||||
{
|
||||
public:
|
||||
forward_adapter(Function const& f = Function())
|
||||
: Function(f)
|
||||
{ }
|
||||
|
||||
typedef Function const target_function_t;
|
||||
typedef Function const target_function_const_t;
|
||||
|
||||
Function const & target_function() const { return *this; }
|
||||
|
||||
template< typename Sig > struct result
|
||||
: detail::forward_adapter_result::template apply<Sig>
|
||||
{ };
|
||||
|
||||
using BOOST_TMP_MACRO(Function const,Function const, Function const)
|
||||
::operator();
|
||||
};
|
||||
template< typename Function, int Arity_Or_MinArity, int MaxArity >
|
||||
class forward_adapter< Function &, Arity_Or_MinArity, MaxArity >
|
||||
: public BOOST_TMP_MACRO(Function&, Function, Function)
|
||||
{
|
||||
Function& ref_function;
|
||||
public:
|
||||
forward_adapter(Function& f)
|
||||
: ref_function(f)
|
||||
{ }
|
||||
|
||||
typedef Function target_function_t;
|
||||
typedef Function target_function_const_t;
|
||||
|
||||
Function & target_function() const { return this->ref_function; }
|
||||
|
||||
template< typename Sig > struct result
|
||||
: detail::forward_adapter_result::template apply<Sig>
|
||||
{ };
|
||||
|
||||
using BOOST_TMP_MACRO(Function&, Function, Function)::operator();
|
||||
};
|
||||
|
||||
#undef BOOST_TMP_MACRO
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< class Self >
|
||||
struct forward_adapter_result::apply< Self() >
|
||||
: boost::result_of< BOOST_DEDUCED_TYPENAME c<Self>::t() >
|
||||
{ };
|
||||
|
||||
// WHen operator()() doesn't have any parameters, it can't
|
||||
// be templatized and can't use SFINAE, so intead use class
|
||||
// template parameter SFINAE to decide whether to instantiate it.
|
||||
|
||||
template <typename T, typename R = void>
|
||||
struct forward_adapter_sfinae
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
// This is the fallback for when there isn't an operator()(),
|
||||
// need to create an operator() that will never instantiate
|
||||
// so that using parent::operator() will work okay.
|
||||
template< class MD, class F, class FC, class Enable = void>
|
||||
struct forward_adapter_impl_zero
|
||||
{
|
||||
template <typename T> struct never_instantiate {};
|
||||
template <typename T>
|
||||
typename never_instantiate<T>::type operator()(T) const {}
|
||||
};
|
||||
|
||||
template< class MD, class F, class FC>
|
||||
struct forward_adapter_impl_zero<MD, F, FC,
|
||||
typename forward_adapter_sfinae<typename boost::result_of< FC() >::type>::type>
|
||||
{
|
||||
inline typename boost::result_of< FC() >::type
|
||||
operator()() const
|
||||
{
|
||||
return static_cast<MD const*>(this)->target_function()();
|
||||
}
|
||||
|
||||
inline typename boost::result_of< F() >::type
|
||||
operator()()
|
||||
{
|
||||
return static_cast<MD*>(this)->target_function()();
|
||||
}
|
||||
};
|
||||
|
||||
template< class MD, class F, class FC >
|
||||
struct forward_adapter_impl<MD,F,FC,0,0>
|
||||
: forward_adapter_impl_zero<MD,F,FC>
|
||||
{
|
||||
using forward_adapter_impl_zero<MD,F,FC>::operator();
|
||||
|
||||
// closing brace gets generated by preprocessing code, below
|
||||
|
||||
# define BOOST_TMP_MACRO(tpl_params,arg_types,params,args) \
|
||||
template< tpl_params > \
|
||||
inline typename boost::result_of< FC(arg_types) >::type \
|
||||
operator()(params) const \
|
||||
{ \
|
||||
return static_cast<MD const*>(this)->target_function()(args); \
|
||||
} \
|
||||
template< tpl_params > \
|
||||
inline typename boost::result_of< F(arg_types)>::type \
|
||||
operator()(params) \
|
||||
{ \
|
||||
return static_cast<MD*>(this)->target_function()(args); \
|
||||
}
|
||||
|
||||
# // This is the total number of iterations we need
|
||||
# define count ((1 << BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY+1)-2)
|
||||
|
||||
# // Chain file iteration to virtually one loop
|
||||
# if BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY <= 7
|
||||
# define limit1 count
|
||||
# define limit2 0
|
||||
# define limit3 0
|
||||
# else
|
||||
# if BOOST_FUNCTIONAL_FORWARD_ADAPTER_MAX_ARITY <= 15
|
||||
# define limit1 (count >> 8)
|
||||
# define limit2 255
|
||||
# define limit3 0
|
||||
# else
|
||||
# define limit1 (count >> 16)
|
||||
# define limit2 255
|
||||
# define limit3 255
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# define N 0
|
||||
|
||||
# define BOOST_PP_FILENAME_1 <boost/functional/forward_adapter.hpp>
|
||||
# define BOOST_PP_ITERATION_LIMITS (0,limit1)
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# undef N
|
||||
# undef limit3
|
||||
# undef limit2
|
||||
# undef limit1
|
||||
# undef count
|
||||
# undef BOOST_TMP_MACRO
|
||||
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::forward_adapter<F,A0,A1> const ()>
|
||||
: boost::detail::forward_adapter_result::template apply<
|
||||
boost::forward_adapter<F,A0,A1> const () >
|
||||
{ };
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::forward_adapter<F,A0,A1>()>
|
||||
: boost::detail::forward_adapter_result::template apply<
|
||||
boost::forward_adapter<F,A0,A1>() >
|
||||
{ };
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::forward_adapter<F,A0,A1> const& ()>
|
||||
: boost::detail::forward_adapter_result::template apply<
|
||||
boost::forward_adapter<F,A0,A1> const () >
|
||||
{ };
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::forward_adapter<F,A0,A1>& ()>
|
||||
: boost::detail::forward_adapter_result::template apply<
|
||||
boost::forward_adapter<F,A0,A1>() >
|
||||
{ };
|
||||
}
|
||||
|
||||
# define BOOST_FUNCTIONAL_FORWARD_ADAPTER_HPP_INCLUDED
|
||||
|
||||
# elif BOOST_PP_ITERATION_DEPTH() == 1 && limit2
|
||||
# define BOOST_PP_FILENAME_2 <boost/functional/forward_adapter.hpp>
|
||||
# define BOOST_PP_ITERATION_LIMITS (0,limit2)
|
||||
# include BOOST_PP_ITERATE()
|
||||
# elif BOOST_PP_ITERATION_DEPTH() == 2 && limit3
|
||||
# define BOOST_PP_FILENAME_3 <boost/functional/forward_adapter.hpp>
|
||||
# define BOOST_PP_ITERATION_LIMITS (0,limit3)
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
# else
|
||||
|
||||
# // I is the loop counter
|
||||
# if limit2 && limit3
|
||||
# define I (BOOST_PP_ITERATION_1 << 16 | BOOST_PP_ITERATION_2 << 8 | \
|
||||
BOOST_PP_ITERATION_3)
|
||||
# elif limit2
|
||||
# define I (BOOST_PP_ITERATION_1 << 8 | BOOST_PP_ITERATION_2)
|
||||
# else
|
||||
# define I BOOST_PP_ITERATION_1
|
||||
# endif
|
||||
|
||||
# if I < count
|
||||
|
||||
# // Done for this arity? Increment N
|
||||
# if (I+2 >> N+1)
|
||||
# if N == 0
|
||||
# undef N
|
||||
# define N 1
|
||||
# elif N == 1
|
||||
# undef N
|
||||
# define N 2
|
||||
# elif N == 2
|
||||
# undef N
|
||||
# define N 3
|
||||
# elif N == 3
|
||||
# undef N
|
||||
# define N 4
|
||||
# elif N == 4
|
||||
# undef N
|
||||
# define N 5
|
||||
# elif N == 5
|
||||
# undef N
|
||||
# define N 6
|
||||
# elif N == 6
|
||||
# undef N
|
||||
# define N 7
|
||||
# elif N == 7
|
||||
# undef N
|
||||
# define N 8
|
||||
# elif N == 8
|
||||
# undef N
|
||||
# define N 9
|
||||
# elif N == 9
|
||||
# undef N
|
||||
# define N 10
|
||||
# elif N == 10
|
||||
# undef N
|
||||
# define N 11
|
||||
# elif N == 11
|
||||
# undef N
|
||||
# define N 12
|
||||
# elif N == 12
|
||||
# undef N
|
||||
# define N 13
|
||||
# elif N == 13
|
||||
# undef N
|
||||
# define N 14
|
||||
# elif N == 14
|
||||
# undef N
|
||||
# define N 15
|
||||
# elif N == 15
|
||||
# undef N
|
||||
# define N 16
|
||||
# endif
|
||||
|
||||
};
|
||||
|
||||
template< class Self, BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
struct forward_adapter_result::apply< Self(BOOST_PP_ENUM_PARAMS(N,T)) >
|
||||
: boost::result_of<
|
||||
BOOST_DEDUCED_TYPENAME c<Self>::t(BOOST_PP_ENUM_BINARY_PARAMS(N,
|
||||
typename q<T,>::t& BOOST_PP_INTERCEPT)) >
|
||||
{ };
|
||||
|
||||
template< class MD, class F, class FC >
|
||||
struct forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),N>
|
||||
{
|
||||
template< BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
inline typename boost::result_of< F(
|
||||
BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)) >::type
|
||||
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT));
|
||||
};
|
||||
|
||||
template< class MD, class F, class FC, int MinArity >
|
||||
struct forward_adapter_impl<MD,F,FC,N,MinArity>
|
||||
: forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>
|
||||
{
|
||||
using forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>::operator();
|
||||
|
||||
# endif
|
||||
|
||||
# // Zero based count for each arity would be I-(1<<N)+2, but we don't
|
||||
# // need it, unless we need a nicer order.
|
||||
|
||||
# // Macros for the parameter's type modifiers.
|
||||
# if I & 0x000001
|
||||
# define PT0 T0 &
|
||||
# else
|
||||
# define PT0 T0 const &
|
||||
# endif
|
||||
# if I & 0x000002
|
||||
# define PT1 T1 &
|
||||
# else
|
||||
# define PT1 T1 const &
|
||||
# endif
|
||||
# if I & 0x000004
|
||||
# define PT2 T2 &
|
||||
# else
|
||||
# define PT2 T2 const &
|
||||
# endif
|
||||
# if I & 0x000008
|
||||
# define PT3 T3 &
|
||||
# else
|
||||
# define PT3 T3 const &
|
||||
# endif
|
||||
# if I & 0x000010
|
||||
# define PT4 T4 &
|
||||
# else
|
||||
# define PT4 T4 const &
|
||||
# endif
|
||||
# if I & 0x000020
|
||||
# define PT5 T5 &
|
||||
# else
|
||||
# define PT5 T5 const &
|
||||
# endif
|
||||
# if I & 0x000040
|
||||
# define PT6 T6 &
|
||||
# else
|
||||
# define PT6 T6 const &
|
||||
# endif
|
||||
# if I & 0x000080
|
||||
# define PT7 T7 &
|
||||
# else
|
||||
# define PT7 T7 const &
|
||||
# endif
|
||||
# if I & 0x000100
|
||||
# define PT8 T8 &
|
||||
# else
|
||||
# define PT8 T8 const &
|
||||
# endif
|
||||
# if I & 0x000200
|
||||
# define PT9 T9 &
|
||||
# else
|
||||
# define PT9 T9 const &
|
||||
# endif
|
||||
# if I & 0x000400
|
||||
# define PT10 T10 &
|
||||
# else
|
||||
# define PT10 T10 const &
|
||||
# endif
|
||||
# if I & 0x000800
|
||||
# define PT11 T11 &
|
||||
# else
|
||||
# define PT11 T11 const &
|
||||
# endif
|
||||
# if I & 0x001000
|
||||
# define PT12 T12 &
|
||||
# else
|
||||
# define PT12 T12 const &
|
||||
# endif
|
||||
# if I & 0x002000
|
||||
# define PT13 T13 &
|
||||
# else
|
||||
# define PT13 T13 const &
|
||||
# endif
|
||||
# if I & 0x004000
|
||||
# define PT14 T14 &
|
||||
# else
|
||||
# define PT14 T14 const &
|
||||
# endif
|
||||
# if I & 0x008000
|
||||
# define PT15 T15 &
|
||||
# else
|
||||
# define PT15 T15 const &
|
||||
# endif
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC,BOOST_TESTED_AT(1400))
|
||||
template< BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
inline typename boost::result_of< FC(BOOST_PP_ENUM_PARAMS(N,PT))
|
||||
>::type
|
||||
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,PT,a)) const
|
||||
{
|
||||
return static_cast<MD const* const>(this)
|
||||
->target_function()(BOOST_PP_ENUM_PARAMS(N,a));
|
||||
}
|
||||
template< BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
inline typename boost::result_of< F(BOOST_PP_ENUM_PARAMS(N,PT))
|
||||
>::type
|
||||
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,PT,a))
|
||||
{
|
||||
return static_cast<MD* const>(this)
|
||||
->target_function()(BOOST_PP_ENUM_PARAMS(N,a));
|
||||
}
|
||||
# else
|
||||
BOOST_TMP_MACRO(BOOST_PP_ENUM_PARAMS(N,typename T),
|
||||
BOOST_PP_ENUM_PARAMS(N,PT), BOOST_PP_ENUM_BINARY_PARAMS(N,PT,a),
|
||||
BOOST_PP_ENUM_PARAMS(N,a) )
|
||||
// ...generates uglier code but is faster - it caches ENUM_*
|
||||
# endif
|
||||
|
||||
# undef PT0
|
||||
# undef PT1
|
||||
# undef PT2
|
||||
# undef PT3
|
||||
# undef PT4
|
||||
# undef PT5
|
||||
# undef PT6
|
||||
# undef PT7
|
||||
# undef PT8
|
||||
# undef PT9
|
||||
# undef PT10
|
||||
# undef PT11
|
||||
# undef PT12
|
||||
# undef PT13
|
||||
# undef PT14
|
||||
# undef PT15
|
||||
|
||||
# endif // I < count
|
||||
|
||||
# undef I
|
||||
# endif // defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
#endif // include guard
|
||||
|
||||
6
include/boost/functional/hash.hpp
Normal file
6
include/boost/functional/hash.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
// Copyright 2005-2009 Daniel James.
|
||||
// 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)
|
||||
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
6
include/boost/functional/hash/extensions.hpp
Normal file
6
include/boost/functional/hash/extensions.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
// Copyright 2017 Daniel James.
|
||||
// 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)
|
||||
|
||||
#include <boost/container_hash/extensions.hpp>
|
||||
6
include/boost/functional/hash/hash.hpp
Normal file
6
include/boost/functional/hash/hash.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
// Copyright 2005-2009 Daniel James.
|
||||
// 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)
|
||||
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
6
include/boost/functional/hash/hash_fwd.hpp
Normal file
6
include/boost/functional/hash/hash_fwd.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
// Copyright 2005-2009 Daniel James.
|
||||
// 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)
|
||||
|
||||
#include <boost/container_hash/hash_fwd.hpp>
|
||||
6
include/boost/functional/hash_fwd.hpp
Normal file
6
include/boost/functional/hash_fwd.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
// Copyright 2005-2009 Daniel James.
|
||||
// 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)
|
||||
|
||||
#include <boost/container_hash/hash_fwd.hpp>
|
||||
17
include/boost/functional/identity.hpp
Normal file
17
include/boost/functional/identity.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
Copyright 2021 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_FUNCTIONAL_IDENTITY_HPP
|
||||
#define BOOST_FUNCTIONAL_IDENTITY_HPP
|
||||
|
||||
/*
|
||||
The header file at this path is deprecated;
|
||||
use <boost/core/identity.hpp> instead.
|
||||
*/
|
||||
#include <boost/core/identity.hpp>
|
||||
|
||||
#endif
|
||||
288
include/boost/functional/lightweight_forward_adapter.hpp
Normal file
288
include/boost/functional/lightweight_forward_adapter.hpp
Normal file
@@ -0,0 +1,288 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2007 Tobias Schwinger
|
||||
|
||||
Use modification and distribution are 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).
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_HPP_INCLUDED
|
||||
# ifndef BOOST_PP_IS_ITERATING
|
||||
|
||||
# include <boost/config.hpp>
|
||||
# include <boost/config/workaround.hpp>
|
||||
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/iteration/iterate.hpp>
|
||||
# include <boost/preprocessor/repetition/enum.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
# include <boost/preprocessor/facilities/intercept.hpp>
|
||||
|
||||
# include <boost/utility/result_of.hpp>
|
||||
# include <boost/ref.hpp>
|
||||
|
||||
# ifndef BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_MAX_ARITY
|
||||
# define BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_MAX_ARITY 10
|
||||
# elif BOOST_FUNCTIONAL_FORDWARD_ADAPTER_MAX_ARITY < 3
|
||||
# undef BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_MAX_ARITY
|
||||
# define BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_MAX_ARITY 3
|
||||
# endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< typename Function, int Arity_Or_MinArity = -1, int MaxArity = -1 >
|
||||
class lightweight_forward_adapter;
|
||||
|
||||
//----- ---- --- -- - - - -
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< class MostDerived, typename Function, typename FunctionConst,
|
||||
int Arity, int MinArity >
|
||||
struct lightweight_forward_adapter_impl;
|
||||
|
||||
struct lightweight_forward_adapter_result
|
||||
{
|
||||
template< typename Sig > struct apply;
|
||||
|
||||
// Utility metafunction for argument transform
|
||||
template< typename T > struct x { typedef T const& t; };
|
||||
template< typename T > struct x< boost::reference_wrapper<T> >
|
||||
{ typedef T& t; };
|
||||
template< typename T > struct x<T&> : x<T> { };
|
||||
template< typename T > struct x<T const&> : x<T> { };
|
||||
template< typename T > struct x<T const> : x<T> { };
|
||||
|
||||
// Utility metafunction to choose target function qualification
|
||||
template< typename T > struct c
|
||||
{ typedef typename T::target_function_t t; };
|
||||
template< typename T > struct c<T& >
|
||||
{ typedef typename T::target_function_t t; };
|
||||
template< typename T > struct c<T const >
|
||||
{ typedef typename T::target_function_const_t t; };
|
||||
template< typename T > struct c<T const&>
|
||||
{ typedef typename T::target_function_const_t t; };
|
||||
};
|
||||
}
|
||||
|
||||
# define BOOST_TMP_MACRO(f,fn,fc) \
|
||||
boost::detail::lightweight_forward_adapter_impl< \
|
||||
lightweight_forward_adapter<f,Arity_Or_MinArity,MaxArity>, fn, fc, \
|
||||
(MaxArity!=-1? MaxArity :Arity_Or_MinArity!=-1? Arity_Or_MinArity \
|
||||
:BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_MAX_ARITY), \
|
||||
(Arity_Or_MinArity!=-1? Arity_Or_MinArity : 0) >
|
||||
|
||||
template< typename Function, int Arity_Or_MinArity, int MaxArity >
|
||||
class lightweight_forward_adapter
|
||||
: public BOOST_TMP_MACRO(Function,Function,Function const)
|
||||
, private Function
|
||||
{
|
||||
public:
|
||||
lightweight_forward_adapter(Function const& f = Function())
|
||||
: Function(f)
|
||||
{ }
|
||||
|
||||
typedef Function target_function_t;
|
||||
typedef Function const target_function_const_t;
|
||||
|
||||
Function & target_function() { return *this; }
|
||||
Function const & target_function() const { return *this; }
|
||||
|
||||
template< typename Sig > struct result
|
||||
: detail::lightweight_forward_adapter_result::template apply<Sig>
|
||||
{ };
|
||||
|
||||
using BOOST_TMP_MACRO(Function,Function, Function const)::operator();
|
||||
};
|
||||
template< typename Function, int Arity_Or_MinArity, int MaxArity >
|
||||
class lightweight_forward_adapter< Function const, Arity_Or_MinArity,
|
||||
MaxArity >
|
||||
: public BOOST_TMP_MACRO(Function const, Function const, Function const)
|
||||
, private Function
|
||||
{
|
||||
public:
|
||||
lightweight_forward_adapter(Function const& f = Function())
|
||||
: Function(f)
|
||||
{ }
|
||||
|
||||
typedef Function const target_function_t;
|
||||
typedef Function const target_function_const_t;
|
||||
|
||||
Function const & target_function() const { return *this; }
|
||||
|
||||
template< typename Sig > struct result
|
||||
: detail::lightweight_forward_adapter_result::template apply<Sig>
|
||||
{ };
|
||||
|
||||
using BOOST_TMP_MACRO(Function const,Function const, Function const)
|
||||
::operator();
|
||||
};
|
||||
template< typename Function, int Arity_Or_MinArity, int MaxArity >
|
||||
class lightweight_forward_adapter< Function &, Arity_Or_MinArity, MaxArity >
|
||||
: public BOOST_TMP_MACRO(Function&, Function, Function)
|
||||
{
|
||||
Function& ref_function;
|
||||
public:
|
||||
lightweight_forward_adapter(Function& f)
|
||||
: ref_function(f)
|
||||
{ }
|
||||
|
||||
typedef Function target_function_t;
|
||||
typedef Function target_function_const_t;
|
||||
|
||||
Function & target_function() const { return this->ref_function; }
|
||||
|
||||
template< typename Sig > struct result
|
||||
: detail::lightweight_forward_adapter_result::template apply<Sig>
|
||||
{ };
|
||||
|
||||
using BOOST_TMP_MACRO(Function&, Function, Function)::operator();
|
||||
};
|
||||
|
||||
#undef BOOST_TMP_MACRO
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< class Self >
|
||||
struct lightweight_forward_adapter_result::apply< Self() >
|
||||
: boost::result_of< BOOST_DEDUCED_TYPENAME c<Self>::t() >
|
||||
{ };
|
||||
|
||||
// When operator() doesn't have any parameters, it can't
|
||||
// be templatized and can't use SFINAE, so intead use class
|
||||
// template parameter SFINAE to decide whether to instantiate it.
|
||||
|
||||
template <typename T, typename R = void>
|
||||
struct lightweight_forward_adapter_sfinae
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
// This is the fallback for when there isn't an operator()(),
|
||||
// need to create an operator() that will never instantiate
|
||||
// so that using parent::operator() will work okay.
|
||||
template< class MD, class F, class FC, class Enable = void>
|
||||
struct lightweight_forward_adapter_impl_zero
|
||||
: lightweight_forward_adapter_result
|
||||
{
|
||||
template <typename T> struct never_instantiate {};
|
||||
template <typename T>
|
||||
typename never_instantiate<T>::type operator()(T) const {}
|
||||
};
|
||||
|
||||
template< class MD, class F, class FC>
|
||||
struct lightweight_forward_adapter_impl_zero<MD, F, FC,
|
||||
typename lightweight_forward_adapter_sfinae<typename boost::result_of< FC() >::type>::type>
|
||||
: lightweight_forward_adapter_result
|
||||
{
|
||||
inline typename boost::result_of< FC() >::type
|
||||
operator()() const
|
||||
{
|
||||
return static_cast<MD const*>(this)->target_function()();
|
||||
}
|
||||
|
||||
inline typename boost::result_of< F() >::type
|
||||
operator()()
|
||||
{
|
||||
return static_cast<MD*>(this)->target_function()();
|
||||
}
|
||||
};
|
||||
|
||||
template< class MD, class F, class FC >
|
||||
struct lightweight_forward_adapter_impl<MD,F,FC,0,0>
|
||||
: lightweight_forward_adapter_impl_zero<MD,F,FC>
|
||||
{
|
||||
};
|
||||
|
||||
# define BOOST_PP_FILENAME_1 \
|
||||
<boost/functional/lightweight_forward_adapter.hpp>
|
||||
# define BOOST_PP_ITERATION_LIMITS \
|
||||
(1,BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_MAX_ARITY)
|
||||
# include BOOST_PP_ITERATE()
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::lightweight_forward_adapter<F,A0,A1> const ()>
|
||||
: boost::detail::lightweight_forward_adapter_result::template apply<
|
||||
boost::lightweight_forward_adapter<F,A0,A1> const () >
|
||||
{ };
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::lightweight_forward_adapter<F,A0,A1>()>
|
||||
: boost::detail::lightweight_forward_adapter_result::template apply<
|
||||
boost::lightweight_forward_adapter<F,A0,A1>() >
|
||||
{ };
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::lightweight_forward_adapter<F,A0,A1> const& ()>
|
||||
: boost::detail::lightweight_forward_adapter_result::template apply<
|
||||
boost::lightweight_forward_adapter<F,A0,A1> const () >
|
||||
{ };
|
||||
template<class F, int A0, int A1>
|
||||
struct result_of<boost::lightweight_forward_adapter<F,A0,A1>& ()>
|
||||
: boost::detail::lightweight_forward_adapter_result::template apply<
|
||||
boost::lightweight_forward_adapter<F,A0,A1>() >
|
||||
{ };
|
||||
}
|
||||
|
||||
# define BOOST_FUNCTIONAL_LIGHTWEIGHT_FORWARD_ADAPTER_HPP_INCLUDED
|
||||
|
||||
# else // defined(BOOST_PP_IS_ITERATING)
|
||||
# define N BOOST_PP_ITERATION()
|
||||
|
||||
template< class Self, BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
struct lightweight_forward_adapter_result::apply<
|
||||
Self (BOOST_PP_ENUM_PARAMS(N,T)) >
|
||||
: boost::result_of<
|
||||
BOOST_DEDUCED_TYPENAME c<Self>::t (BOOST_PP_ENUM_BINARY_PARAMS(N,
|
||||
typename x<T,>::t BOOST_PP_INTERCEPT)) >
|
||||
{ };
|
||||
|
||||
template< class MD, class F, class FC >
|
||||
struct lightweight_forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),N>
|
||||
: lightweight_forward_adapter_result
|
||||
{
|
||||
template< BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
inline typename boost::result_of< F(BOOST_PP_ENUM_BINARY_PARAMS(N,
|
||||
T,const& BOOST_PP_INTERCEPT)) >::type
|
||||
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT));
|
||||
};
|
||||
|
||||
template< class MD, class F, class FC, int MinArity >
|
||||
struct lightweight_forward_adapter_impl<MD,F,FC,N,MinArity>
|
||||
: lightweight_forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),MinArity>
|
||||
{
|
||||
using lightweight_forward_adapter_impl<MD,F,FC,BOOST_PP_DEC(N),
|
||||
MinArity>::operator();
|
||||
|
||||
# define M(z,i,d) \
|
||||
static_cast<typename d::template x<T##i>::t>(a##i)
|
||||
|
||||
template< BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
inline typename lightweight_forward_adapter_result::template apply<
|
||||
MD const (BOOST_PP_ENUM_BINARY_PARAMS(N,
|
||||
T,const& BOOST_PP_INTERCEPT)) >::type
|
||||
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& a)) const
|
||||
{
|
||||
typedef lightweight_forward_adapter_result _;
|
||||
return static_cast<MD const*>(this)->target_function()(
|
||||
BOOST_PP_ENUM(N,M,_));
|
||||
}
|
||||
template< BOOST_PP_ENUM_PARAMS(N,typename T) >
|
||||
inline typename lightweight_forward_adapter_result::template apply<
|
||||
MD (BOOST_PP_ENUM_BINARY_PARAMS(N,
|
||||
T,const& BOOST_PP_INTERCEPT)) >::type
|
||||
operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,const& a))
|
||||
{
|
||||
typedef lightweight_forward_adapter_result _;
|
||||
return static_cast<MD*>(this)->target_function()(
|
||||
BOOST_PP_ENUM(N,M,_));
|
||||
}
|
||||
# undef M
|
||||
};
|
||||
|
||||
# undef N
|
||||
# endif // defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
#endif // include guard
|
||||
|
||||
311
include/boost/functional/overloaded_function.hpp
Normal file
311
include/boost/functional/overloaded_function.hpp
Normal file
@@ -0,0 +1,311 @@
|
||||
|
||||
// Copyright (C) 2009-2012 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// (see accompanying file LICENSE_1_0.txt or a copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
// Home at http://www.boost.org/libs/functional/overloaded_function
|
||||
|
||||
#ifndef DOXYGEN // Doxygen documentation only.
|
||||
|
||||
#if !BOOST_PP_IS_ITERATING
|
||||
# ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
|
||||
# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_HPP_
|
||||
|
||||
# include <boost/functional/overloaded_function/detail/base.hpp>
|
||||
# include <boost/functional/overloaded_function/detail/function_type.hpp>
|
||||
# include <boost/functional/overloaded_function/config.hpp>
|
||||
# include <boost/typeof/typeof.hpp>
|
||||
# include <boost/preprocessor/iteration/iterate.hpp>
|
||||
# include <boost/preprocessor/repetition/enum.hpp>
|
||||
# include <boost/preprocessor/repetition/repeat.hpp>
|
||||
# include <boost/preprocessor/control/expr_iif.hpp>
|
||||
# include <boost/preprocessor/control/expr_if.hpp>
|
||||
# include <boost/preprocessor/comparison/greater.hpp>
|
||||
# include <boost/preprocessor/comparison/less.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/arithmetic/add.hpp>
|
||||
# include <boost/preprocessor/arithmetic/sub.hpp>
|
||||
# include <boost/preprocessor/tuple/eat.hpp>
|
||||
# include <boost/preprocessor/logical/and.hpp>
|
||||
# include <boost/preprocessor/logical/not.hpp>
|
||||
# include <boost/preprocessor/facilities/expand.hpp>
|
||||
|
||||
#define BOOST_FUNCTIONAL_f_type(z, n, unused) \
|
||||
BOOST_PP_CAT(F, n)
|
||||
|
||||
#define BOOST_FUNCTIONAL_f_arg(z, n, unused) \
|
||||
BOOST_PP_CAT(f, n)
|
||||
|
||||
#define BOOST_FUNCTIONAL_f_tparam(z, n, unused) \
|
||||
typename BOOST_FUNCTIONAL_f_type(z, n, ~) \
|
||||
|
||||
#define BOOST_FUNCTIONAL_f_tparam_dflt(z, n, is_tspec) \
|
||||
BOOST_FUNCTIONAL_f_tparam(z, n, ~) \
|
||||
/* overload requires at least 2 functors so F0 and F1 not optional */ \
|
||||
BOOST_PP_EXPR_IIF(BOOST_PP_AND(BOOST_PP_NOT(is_tspec), \
|
||||
BOOST_PP_GREATER(n, 1)), \
|
||||
= void \
|
||||
)
|
||||
|
||||
#define BOOST_FUNCTIONAL_f_arg_decl(z, n, unused) \
|
||||
BOOST_FUNCTIONAL_f_type(z, n, ~) /* no qualifier to deduce tparam */ \
|
||||
BOOST_FUNCTIONAL_f_arg(z, n, ~)
|
||||
|
||||
#define BOOST_FUNCTIONAL_g_type(z, n, unused) \
|
||||
BOOST_PP_CAT(G, n)
|
||||
|
||||
#define BOOST_FUNCTIONAL_g_arg(z, n, unused) \
|
||||
BOOST_PP_CAT(g, n)
|
||||
|
||||
#define BOOST_FUNCTIONAL_g_tparam(z, n, unused) \
|
||||
typename BOOST_FUNCTIONAL_g_type(z, n, ~)
|
||||
|
||||
#define BOOST_FUNCTIONAL_g_arg_decl(z, n, unused) \
|
||||
BOOST_FUNCTIONAL_g_type(z, n, ~) /* no qualifier to deduce tparam */ \
|
||||
BOOST_FUNCTIONAL_g_arg(z, n, ~)
|
||||
|
||||
#define BOOST_FUNCTIONAL_base(z, n, unused) \
|
||||
::boost::overloaded_function_detail::base< \
|
||||
BOOST_FUNCTIONAL_f_type(z, n, ~) \
|
||||
>
|
||||
|
||||
#define BOOST_FUNCTIONAL_inherit(z, n, unused) \
|
||||
public BOOST_FUNCTIONAL_base(z, n, ~)
|
||||
|
||||
#define BOOST_FUNCTIONAL_base_init(z, n, unused) \
|
||||
BOOST_FUNCTIONAL_base(z, n, ~)(BOOST_FUNCTIONAL_g_arg(z, n, ~))
|
||||
|
||||
#define BOOST_FUNCTIONAL_using_operator_call(z, n, unused) \
|
||||
using BOOST_FUNCTIONAL_base(z, n, ~)::operator();
|
||||
|
||||
#define BOOST_FUNCTIONAL_function_type(z, n, unused) \
|
||||
typename ::boost::overloaded_function_detail::function_type< \
|
||||
BOOST_FUNCTIONAL_f_type(z, n, ~) \
|
||||
>::type
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
/* at least 2 func to overload so start from 2 to MAX */ \
|
||||
/* (cannot iterate [0, MAX-2) because error on Sun) */ \
|
||||
(3, (2, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
|
||||
"boost/functional/overloaded_function.hpp"))
|
||||
# include BOOST_PP_ITERATE() // Iterate over function arity.
|
||||
|
||||
#undef BOOST_FUNCTIONAL_f_type
|
||||
#undef BOOST_FUNCTIONAL_f_arg
|
||||
#undef BOOST_FUNCTIONAL_f_tparam
|
||||
#undef BOOST_FUNCTIONAL_f_arg_decl
|
||||
#undef BOOST_FUNCTIONAL_f_tparam_dflt
|
||||
#undef BOOST_FUNCTIONAL_g_type
|
||||
#undef BOOST_FUNCTIONAL_g_arg
|
||||
#undef BOOST_FUNCTIONAL_g_tparam
|
||||
#undef BOOST_FUNCTIONAL_g_arg_decl
|
||||
#undef BOOST_FUNCTIONAL_base
|
||||
#undef BOOST_FUNCTIONAL_inherit
|
||||
#undef BOOST_FUNCTIONAL_base_init
|
||||
#undef BOOST_FUNCTIONAL_using_operator_call
|
||||
#undef BOOST_FUNCTIONAL_function_type
|
||||
|
||||
# endif // #include guard
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# define BOOST_FUNCTIONAL_overloads \
|
||||
/* iterate as OVERLOADS, OVERLOADS-1, OVERLOADS-2, ... */ \
|
||||
/* (add 2 because iteration started from 2 to MAX) */ \
|
||||
BOOST_PP_ADD(2, BOOST_PP_SUB( \
|
||||
BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX, \
|
||||
BOOST_PP_FRAME_ITERATION(1)))
|
||||
# define BOOST_FUNCTIONAL_is_tspec \
|
||||
/* if template specialization */ \
|
||||
BOOST_PP_LESS(BOOST_FUNCTIONAL_overloads, \
|
||||
BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX)
|
||||
|
||||
// For type-of emulation: This must be included at this pp iteration level.
|
||||
# include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam_dflt,
|
||||
BOOST_FUNCTIONAL_is_tspec)
|
||||
>
|
||||
class overloaded_function
|
||||
// Template specialization.
|
||||
BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_FUNCTIONAL_is_tspec), <)
|
||||
BOOST_PP_IIF(BOOST_FUNCTIONAL_is_tspec,
|
||||
BOOST_PP_ENUM
|
||||
,
|
||||
BOOST_PP_TUPLE_EAT(3)
|
||||
)(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_type, ~)
|
||||
BOOST_PP_EXPR_IIF(BOOST_PP_EXPAND(BOOST_FUNCTIONAL_is_tspec), >)
|
||||
// Bases (overloads >= 2 so always at least 2 bases).
|
||||
: BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
|
||||
BOOST_FUNCTIONAL_inherit, ~)
|
||||
{
|
||||
public:
|
||||
template<
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_g_tparam, ~)
|
||||
> /* implicit */ inline overloaded_function(
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
|
||||
BOOST_FUNCTIONAL_g_arg_decl, ~))
|
||||
// Overloads >= 2 so always at least 2 bases to initialize.
|
||||
: BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
|
||||
BOOST_FUNCTIONAL_base_init, ~)
|
||||
{}
|
||||
|
||||
BOOST_PP_REPEAT(BOOST_FUNCTIONAL_overloads,
|
||||
BOOST_FUNCTIONAL_using_operator_call, ~)
|
||||
};
|
||||
|
||||
template<
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_tparam, ~)
|
||||
>
|
||||
overloaded_function<
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_function_type, ~)
|
||||
> make_overloaded_function(
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg_decl, ~)
|
||||
) {
|
||||
return overloaded_function<
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads,
|
||||
BOOST_FUNCTIONAL_function_type, ~)
|
||||
>(BOOST_PP_ENUM(BOOST_FUNCTIONAL_overloads, BOOST_FUNCTIONAL_f_arg, ~));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// For type-of emulation: Register overloaded function type (for _AUTO, etc).
|
||||
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::overloaded_function,
|
||||
BOOST_FUNCTIONAL_overloads)
|
||||
|
||||
# undef BOOST_FUNCTIONAL_overloads
|
||||
# undef BOOST_FUNCTIONAL_is_tspec
|
||||
#endif // iteration
|
||||
|
||||
// DOCUMENTATION //
|
||||
|
||||
#else // DOXYGEN
|
||||
|
||||
/** @file
|
||||
@brief Overload distinct function pointers, function references, and
|
||||
monomorphic function objects into a single function object.
|
||||
*/
|
||||
|
||||
namespace boost {
|
||||
|
||||
/**
|
||||
@brief Function object to overload functions with distinct signatures.
|
||||
|
||||
This function object aggregates together calls to functions of all the
|
||||
specified function types <c>F1</c>, <c>F2</c>, etc which must have distinct
|
||||
function signatures from one another.
|
||||
|
||||
@Params
|
||||
@Param{F<em>i</em>,
|
||||
Each function type must be specified using the following syntax (which is
|
||||
Boost.Function's preferred syntax):
|
||||
@code
|
||||
result_type (argument1_type\, argumgnet2_type\, ...)
|
||||
@endcode
|
||||
}
|
||||
@EndParams
|
||||
|
||||
In some cases, the @RefFunc{make_overloaded_function} function template can be
|
||||
useful to construct an overloaded function object without explicitly
|
||||
specifying the function types.
|
||||
|
||||
At least two distinct function types must be specified (because there is
|
||||
nothing to overload between one or zero functions).
|
||||
The maximum number of functions to overload is given by the
|
||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
|
||||
configuration macro.
|
||||
The maximum number of function parameters for each of the specified function
|
||||
types is given by the
|
||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX}
|
||||
configuration macro.
|
||||
|
||||
@See @RefSect{tutorial, Tutorial} section, @RefFunc{make_overloaded_function},
|
||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX},
|
||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX},
|
||||
Boost.Function.
|
||||
*/
|
||||
template<typename F1, typename F2, ...>
|
||||
class overloaded_function {
|
||||
public:
|
||||
/**
|
||||
@brief Construct the overloaded function object.
|
||||
|
||||
Any function pointer, function reference, and monomorphic function object
|
||||
that can be converted to a <c>boost::function</c> function object can be
|
||||
specified as parameter.
|
||||
|
||||
@Note Unfortunately, it is not possible to support polymorphic function
|
||||
objects (as explained <a
|
||||
href="http://lists.boost.org/Archives/boost/2012/03/191744.php">here</a>).
|
||||
*/
|
||||
overloaded_function(const boost::function<F1>&,
|
||||
const boost::function<F2>&, ...);
|
||||
|
||||
/**
|
||||
@brief Call operator matching the signature of the function type specified
|
||||
as 1st template parameter.
|
||||
|
||||
This will in turn invoke the call operator of the 1st function passed to
|
||||
the constructor.
|
||||
*/
|
||||
typename boost::function_traits<F1>::result_type operator()(
|
||||
typename boost::function_traits<F1>::arg1_type,
|
||||
typename boost::function_traits<F1>::arg2_type,
|
||||
...) const;
|
||||
|
||||
/**
|
||||
@brief Call operator matching the signature of the function type specified
|
||||
as 2nd template parameter.
|
||||
|
||||
This will in turn invoke the call operator of the 2nd function passed to
|
||||
the constructor.
|
||||
|
||||
@Note Similar call operators are present for all specified function types
|
||||
<c>F1</c>, <c>F2</c>, etc (even if not exhaustively listed by this
|
||||
documentation).
|
||||
*/
|
||||
typename boost::function_traits<F2>::result_type operator()(
|
||||
typename boost::function_traits<F2>::arg1_type,
|
||||
typename boost::function_traits<F2>::arg2_type,
|
||||
...) const;
|
||||
};
|
||||
|
||||
/**
|
||||
@brief Make an overloaded function object without explicitly specifying the
|
||||
function types.
|
||||
|
||||
This function template creates and returns an @RefClass{overloaded_function}
|
||||
object that overloads all the specified functions <c>f1</c>, <c>f2</c>, etc.
|
||||
|
||||
The function types are internally determined from the template parameter types
|
||||
so they do not need to be explicitly specified.
|
||||
Therefore, this function template usually has a more concise syntax when
|
||||
compared with @RefClass{overloaded_function}.
|
||||
This is especially useful when the explicit type of the returned
|
||||
@RefClass{overloaded_function} object does not need to be known (e.g., when
|
||||
used with Boost.Typeof's <c>BOOST_AUTO</c>, C++11 <c>auto</c>, or when the
|
||||
overloaded function object is handled using a function template parameter, see
|
||||
the @RefSect{tutorial, Tutorial} section).
|
||||
|
||||
The maximum number of functions to overload is given by the
|
||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}
|
||||
configuration macro.
|
||||
|
||||
@Note In this documentation, <c>__function_type__</c> is a placeholder for a
|
||||
symbol that is specific to the implementation of this library.
|
||||
|
||||
@See @RefSect{tutorial, Tutorial} section, @RefClass{overloaded_function},
|
||||
@RefMacro{BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX}.
|
||||
*/
|
||||
template<typename F1, typename F2, ...>
|
||||
overloaded_function<
|
||||
__function_type__<F1>, __function_type__<F2>, ...
|
||||
> make_overloaded_function(F1 f1, F2 f2, ...);
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // DOXYGEN
|
||||
|
||||
50
include/boost/functional/overloaded_function/config.hpp
Normal file
50
include/boost/functional/overloaded_function/config.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
// Copyright (C) 2009-2012 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// (see accompanying file LICENSE_1_0.txt or a copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
// Home at http://www.boost.org/libs/functional/overloaded_function
|
||||
|
||||
#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_HPP_
|
||||
#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_HPP_
|
||||
|
||||
/** @file
|
||||
@brief Change the compile-time configuration of this library.
|
||||
*/
|
||||
|
||||
/**
|
||||
@brief Specify the maximum number of arguments of the functions being
|
||||
overloaded.
|
||||
|
||||
If this macro is left undefined by the user, it has a default value of 5
|
||||
(increasing this number might increase compilation time).
|
||||
When specified by the user, this macro must be a non-negative integer number.
|
||||
|
||||
@See @RefSect{getting_started, Getting Started},
|
||||
@RefClass{boost::overloaded_function}.
|
||||
*/
|
||||
#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX
|
||||
# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX 5
|
||||
#endif
|
||||
|
||||
/**
|
||||
@brief Specify the maximum number of functions that can be overloaded.
|
||||
|
||||
If this macro is left undefined by the user, it has a default value of 5
|
||||
(increasing this number might increase compilation time).
|
||||
When defined by the user, this macro must be an integer number greater or
|
||||
equal than 2 (because at least two distinct functions need to be specified in
|
||||
order to define an overload).
|
||||
|
||||
@See @RefSect{getting_started, Getting Started},
|
||||
@RefClass{boost::overloaded_function}.
|
||||
*/
|
||||
#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX
|
||||
# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX 5
|
||||
#endif
|
||||
#if BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_OVERLOAD_MAX < 2
|
||||
# error "maximum overload macro cannot be less than 2"
|
||||
#endif
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
86
include/boost/functional/overloaded_function/detail/base.hpp
Normal file
86
include/boost/functional/overloaded_function/detail/base.hpp
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
// Copyright (C) 2009-2012 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// (see accompanying file LICENSE_1_0.txt or a copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
// Home at http://www.boost.org/libs/functional/overloaded_function
|
||||
|
||||
#if !BOOST_PP_IS_ITERATING
|
||||
# ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
|
||||
# define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_
|
||||
|
||||
# include <boost/functional/overloaded_function/config.hpp>
|
||||
# include <boost/function.hpp>
|
||||
# include <boost/preprocessor/iteration/iterate.hpp>
|
||||
# include <boost/preprocessor/repetition/enum.hpp>
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/comma_if.hpp>
|
||||
|
||||
#define BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \
|
||||
BOOST_PP_CAT(A, n)
|
||||
|
||||
#define BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused) \
|
||||
BOOST_PP_CAT(a, n)
|
||||
|
||||
#define BOOST_FUNCTIONAL_DETAIL_arg_tparam(z, n, unused) \
|
||||
typename BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused)
|
||||
|
||||
#define BOOST_FUNCTIONAL_DETAIL_arg(z, n, unused) \
|
||||
BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \
|
||||
BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused)
|
||||
|
||||
#define BOOST_FUNCTIONAL_DETAIL_f \
|
||||
R (BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, \
|
||||
BOOST_FUNCTIONAL_DETAIL_arg_type, ~))
|
||||
|
||||
// Do not use namespace ::detail because overloaded_function is already a class.
|
||||
namespace boost { namespace overloaded_function_detail {
|
||||
|
||||
template<typename F>
|
||||
class base {}; // Empty template cannot be used directly (only its spec).
|
||||
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, \
|
||||
"boost/functional/overloaded_function/detail/base.hpp"))
|
||||
# include BOOST_PP_ITERATE() // Iterate over funciton arity.
|
||||
|
||||
} } // namespace
|
||||
|
||||
#undef BOOST_FUNCTIONAL_DETAIL_arg_type
|
||||
#undef BOOST_FUNCTIONAL_DETAIL_arg_name
|
||||
#undef BOOST_FUNCTIONAL_DETAIL_arg_tparam
|
||||
#undef BOOST_FUNCTIONAL_DETAIL_arg
|
||||
#undef BOOST_FUNCTIONAL_DETAIL_f
|
||||
|
||||
# endif // #include guard
|
||||
|
||||
#elif BOOST_PP_ITERATION_DEPTH() == 1
|
||||
# define BOOST_FUNCTIONAL_DETAIL_arity BOOST_PP_FRAME_ITERATION(1)
|
||||
|
||||
template<
|
||||
typename R
|
||||
BOOST_PP_COMMA_IF(BOOST_FUNCTIONAL_DETAIL_arity)
|
||||
BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
|
||||
BOOST_FUNCTIONAL_DETAIL_arg_tparam, ~)
|
||||
>
|
||||
class base< BOOST_FUNCTIONAL_DETAIL_f > {
|
||||
public:
|
||||
/* implicit */ inline base(
|
||||
// This requires specified type to be implicitly convertible to
|
||||
// a boost::function<> functor.
|
||||
boost::function< BOOST_FUNCTIONAL_DETAIL_f > const& f): f_(f)
|
||||
{}
|
||||
|
||||
inline R operator()(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
|
||||
BOOST_FUNCTIONAL_DETAIL_arg, ~)) const {
|
||||
return f_(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity,
|
||||
BOOST_FUNCTIONAL_DETAIL_arg_name, ~));
|
||||
}
|
||||
|
||||
private:
|
||||
boost::function< BOOST_FUNCTIONAL_DETAIL_f > const f_;
|
||||
};
|
||||
|
||||
# undef BOOST_FUNCTIONAL_DETAIL_arity
|
||||
#endif // iteration
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
// Copyright (C) 2009-2012 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// (see accompanying file LICENSE_1_0.txt or a copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
// Home at http://www.boost.org/libs/functional/overloaded_function
|
||||
|
||||
#ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_FUNCTION_TYPE_HPP_
|
||||
#define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_FUNCTION_TYPE_HPP_
|
||||
|
||||
#include <boost/function_types/is_function.hpp>
|
||||
#include <boost/function_types/is_function_pointer.hpp>
|
||||
#include <boost/function_types/is_function_reference.hpp>
|
||||
#include <boost/function_types/function_type.hpp>
|
||||
#include <boost/function_types/parameter_types.hpp>
|
||||
#include <boost/function_types/result_type.hpp>
|
||||
#include <boost/type_traits/remove_pointer.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/mpl/pop_front.hpp>
|
||||
#include <boost/mpl/push_front.hpp>
|
||||
#include <boost/typeof/typeof.hpp>
|
||||
|
||||
// Do not use namespace ::detail because overloaded_function is already a class.
|
||||
namespace boost { namespace overloaded_function_detail {
|
||||
|
||||
// Requires: F is a monomorphic functor (i.e., has non-template `operator()`).
|
||||
// Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
|
||||
// It does not assume F typedef result_type, arg1_type, ... but needs typeof.
|
||||
template<typename F>
|
||||
class functor_type {
|
||||
// NOTE: clang does not accept extra parenthesis `&(...)`.
|
||||
typedef BOOST_TYPEOF_TPL(&F::operator()) call_ptr;
|
||||
public:
|
||||
typedef
|
||||
typename boost::function_types::function_type<
|
||||
typename boost::mpl::push_front<
|
||||
typename boost::mpl::pop_front< // Remove functor type (1st).
|
||||
typename boost::function_types::parameter_types<
|
||||
call_ptr>::type
|
||||
>::type
|
||||
, typename boost::function_types::result_type<call_ptr>::type
|
||||
>::type
|
||||
>::type
|
||||
type;
|
||||
};
|
||||
|
||||
// NOTE: When using boost::function in Boost.Typeof emulation mode, the user
|
||||
// has to register boost::functionN instead of boost::function in oder to
|
||||
// do TYPEOF(F::operator()). That is confusing, so boost::function is handled
|
||||
// separately so it does not require any Boost.Typeof registration at all.
|
||||
template<typename F>
|
||||
struct functor_type< boost::function<F> > {
|
||||
typedef F type;
|
||||
};
|
||||
|
||||
// Requires: F is a function type, pointer, reference, or monomorphic functor.
|
||||
// Returns: F's function type `result_type (arg1_type, arg2_type, ...)`.
|
||||
template<typename F>
|
||||
struct function_type {
|
||||
typedef
|
||||
typename boost::mpl::if_<boost::function_types::is_function<F>,
|
||||
boost::mpl::identity<F>
|
||||
,
|
||||
typename boost::mpl::if_<boost::function_types::
|
||||
is_function_pointer<F>,
|
||||
boost::remove_pointer<F>
|
||||
,
|
||||
typename boost::mpl::if_<boost::function_types::
|
||||
is_function_reference<F>,
|
||||
boost::remove_reference<F>
|
||||
, // Else, requires that F is a functor.
|
||||
functor_type<F>
|
||||
>::type
|
||||
>::type
|
||||
>::type
|
||||
::type type;
|
||||
};
|
||||
|
||||
} } // namespace
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
106
include/boost/functional/value_factory.hpp
Normal file
106
include/boost/functional/value_factory.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
Copyright 2007 Tobias Schwinger
|
||||
|
||||
Copyright 2019 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_FUNCTIONAL_VALUE_FACTORY_HPP
|
||||
#define BOOST_FUNCTIONAL_VALUE_FACTORY_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
class value_factory;
|
||||
|
||||
template<class T>
|
||||
class value_factory {
|
||||
public:
|
||||
typedef T result_type;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
template<class... Args>
|
||||
result_type operator()(Args&&... args) const {
|
||||
return result_type(std::forward<Args>(args)...);
|
||||
}
|
||||
#else
|
||||
result_type operator()() const {
|
||||
return result_type();
|
||||
}
|
||||
|
||||
template<class A0>
|
||||
result_type operator()(A0& a0) const {
|
||||
return result_type(a0);
|
||||
}
|
||||
|
||||
template<class A0, class A1>
|
||||
result_type operator()(A0& a0, A1& a1) const {
|
||||
return result_type(a0, a1);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2) const {
|
||||
return result_type(a0, a1, a2);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3) const {
|
||||
return result_type(a0, a1, a2, a3);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4) const {
|
||||
return result_type(a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4,
|
||||
A5& a5) const {
|
||||
return result_type(a0, a1, a2, a3, a4, a5);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6) const {
|
||||
return result_type(a0, a1, a2, a3, a4, a5, a6);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7) const {
|
||||
return result_type(a0, a1, a2, a3, a4, a5, a6, a7);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7, class A8>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7, A8& a8) const {
|
||||
return result_type(a0, a1, a2, a3, a4, a5, a6, a7, a8);
|
||||
}
|
||||
|
||||
template<class A0, class A1, class A2, class A3, class A4, class A5,
|
||||
class A6, class A7, class A8, class A9>
|
||||
result_type operator()(A0& a0, A1& a1, A2& a2, A3& a3, A4& a4, A5& a5,
|
||||
A6& a6, A7& a7, A8& a8, A9& a9) const {
|
||||
return result_type(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class value_factory<T&> { };
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user