// TR1 functional header -*- C++ -*-
// Copyright (C) 2004-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// .
/** @file tr1/functional
* This is a TR1 C++ Library header.
*/
#ifndef _GLIBCXX_TR1_FUNCTIONAL
#define _GLIBCXX_TR1_FUNCTIONAL 1
#pragma GCC system_header
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include // for std::__addressof
#if __cplusplus >= 201103L
# include // for integral_constant, true_type, false_type
#endif
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
template struct _Placeholder;
template class _Bind;
template class _Bind_result;
#endif
namespace tr1
{
template
class _Mem_fn;
template
_Mem_fn<_Tp _Class::*>
mem_fn(_Tp _Class::*);
/**
* Actual implementation of _Has_result_type, which uses SFINAE to
* determine if the type _Tp has a publicly-accessible member type
* result_type.
*/
template
class _Has_result_type_helper : __sfinae_types
{
template
struct _Wrap_type
{ };
template
static __one __test(_Wrap_type*);
template
static __two __test(...);
public:
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
template
struct _Has_result_type
: integral_constant::type>::value>
{ };
/**
*
*/
/// If we have found a result_type, extract it.
template
struct _Maybe_get_result_type
{ };
template
struct _Maybe_get_result_type
{
typedef typename _Functor::result_type result_type;
};
/**
* Base class for any function object that has a weak result type, as
* defined in 3.3/3 of TR1.
*/
template
struct _Weak_result_type_impl
: _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor>
{
};
/// Retrieve the result type for a function type.
template
struct _Weak_result_type_impl<_Res(_ArgTypes...)>
{
typedef _Res result_type;
};
/// Retrieve the result type for a function reference.
template
struct _Weak_result_type_impl<_Res(&)(_ArgTypes...)>
{
typedef _Res result_type;
};
/// Retrieve the result type for a function pointer.
template
struct _Weak_result_type_impl<_Res(*)(_ArgTypes...)>
{
typedef _Res result_type;
};
/// Retrieve result type for a member function pointer.
template
struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)>
{
typedef _Res result_type;
};
/// Retrieve result type for a const member function pointer.
template
struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) const>
{
typedef _Res result_type;
};
/// Retrieve result type for a volatile member function pointer.
template
struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) volatile>
{
typedef _Res result_type;
};
/// Retrieve result type for a const volatile member function pointer.
template
struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)const volatile>
{
typedef _Res result_type;
};
/**
* Strip top-level cv-qualifiers from the function object and let
* _Weak_result_type_impl perform the real work.
*/
template
struct _Weak_result_type
: _Weak_result_type_impl::type>
{
};
template
class result_of;
/**
* Actual implementation of result_of. When _Has_result_type is
* true, gets its result from _Weak_result_type. Otherwise, uses
* the function object's member template result to extract the
* result type.
*/
template
struct _Result_of_impl;
// Handle member data pointers using _Mem_fn's logic
template
struct _Result_of_impl
{
typedef typename _Mem_fn<_Res _Class::*>
::template _Result_type<_T1>::type type;
};
/**
* Determine whether we can determine a result type from @c Functor
* alone.
*/
template
class result_of<_Functor(_ArgTypes...)>
: public _Result_of_impl<
_Has_result_type<_Weak_result_type<_Functor> >::value,
_Functor(_ArgTypes...)>
{
};
/// We already know the result type for @c Functor; use it.
template
struct _Result_of_impl
{
typedef typename _Weak_result_type<_Functor>::result_type type;
};
/**
* We need to compute the result type for this invocation the hard
* way.
*/
template
struct _Result_of_impl
{
typedef typename _Functor
::template result<_Functor(_ArgTypes...)>::type type;
};
/**
* It is unsafe to access ::result when there are zero arguments, so we
* return @c void instead.
*/
template
struct _Result_of_impl
{
typedef void type;
};
/// Determines if the type _Tp derives from unary_function.
template
struct _Derives_from_unary_function : __sfinae_types
{
private:
template
static __one __test(const volatile unary_function<_T1, _Res>*);
// It's tempting to change "..." to const volatile void*, but
// that fails when _Tp is a function type.
static __two __test(...);
public:
static const bool value = sizeof(__test((_Tp*)0)) == 1;
};
/// Determines if the type _Tp derives from binary_function.
template
struct _Derives_from_binary_function : __sfinae_types
{
private:
template
static __one __test(const volatile binary_function<_T1, _T2, _Res>*);
// It's tempting to change "..." to const volatile void*, but
// that fails when _Tp is a function type.
static __two __test(...);
public:
static const bool value = sizeof(__test((_Tp*)0)) == 1;
};
/// Turns a function type into a function pointer type
template::value>
struct _Function_to_function_pointer
{
typedef _Tp type;
};
template
struct _Function_to_function_pointer<_Tp, true>
{
typedef _Tp* type;
};
/**
* Invoke a function object, which may be either a member pointer or a
* function object. The first parameter will tell which.
*/
template
inline
typename __gnu_cxx::__enable_if<
(!is_member_pointer<_Functor>::value
&& !is_function<_Functor>::value
&& !is_function::type>::value),
typename result_of<_Functor(_Args...)>::type
>::__type
__invoke(_Functor& __f, _Args&... __args)
{
return __f(__args...);
}
template
inline
typename __gnu_cxx::__enable_if<
(is_member_pointer<_Functor>::value
&& !is_function<_Functor>::value
&& !is_function::type>::value),
typename result_of<_Functor(_Args...)>::type
>::__type
__invoke(_Functor& __f, _Args&... __args)
{
return mem_fn(__f)(__args...);
}
// To pick up function references (that will become function pointers)
template
inline
typename __gnu_cxx::__enable_if<
(is_pointer<_Functor>::value
&& is_function::type>::value),
typename result_of<_Functor(_Args...)>::type
>::__type
__invoke(_Functor __f, _Args&... __args)
{
return __f(__args...);
}
/**
* Knowing which of unary_function and binary_function _Tp derives
* from, derives from the same and ensures that reference_wrapper
* will have a weak result type. See cases below.
*/
template
struct _Reference_wrapper_base_impl;
// Not a unary_function or binary_function, so try a weak result type.
template
struct _Reference_wrapper_base_impl
: _Weak_result_type<_Tp>
{ };
// unary_function but not binary_function
template
struct _Reference_wrapper_base_impl
: unary_function
{ };
// binary_function but not unary_function
template
struct _Reference_wrapper_base_impl
: binary_function
{ };
// Both unary_function and binary_function. Import result_type to
// avoid conflicts.
template
struct _Reference_wrapper_base_impl
: unary_function,
binary_function
{
typedef typename _Tp::result_type result_type;
};
/**
* Derives from unary_function or binary_function when it
* can. Specializations handle all of the easy cases. The primary
* template determines what to do with a class type, which may
* derive from both unary_function and binary_function.
*/
template
struct _Reference_wrapper_base
: _Reference_wrapper_base_impl<
_Derives_from_unary_function<_Tp>::value,
_Derives_from_binary_function<_Tp>::value,
_Tp>
{ };
// - a function type (unary)
template
struct _Reference_wrapper_base<_Res(_T1)>
: unary_function<_T1, _Res>
{ };
// - a function type (binary)
template
struct _Reference_wrapper_base<_Res(_T1, _T2)>
: binary_function<_T1, _T2, _Res>
{ };
// - a function pointer type (unary)
template
struct _Reference_wrapper_base<_Res(*)(_T1)>
: unary_function<_T1, _Res>
{ };
// - a function pointer type (binary)
template
struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>
: binary_function<_T1, _T2, _Res>
{ };
// - a pointer to member function type (unary, no qualifiers)
template
struct _Reference_wrapper_base<_Res (_T1::*)()>
: unary_function<_T1*, _Res>
{ };
// - a pointer to member function type (binary, no qualifiers)
template
struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>
: binary_function<_T1*, _T2, _Res>
{ };
// - a pointer to member function type (unary, const)
template
struct _Reference_wrapper_base<_Res (_T1::*)() const>
: unary_function
{ };
// - a pointer to member function type (binary, const)
template
struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>
: binary_function
{ };
// - a pointer to member function type (unary, volatile)
template
struct _Reference_wrapper_base<_Res (_T1::*)() volatile>
: unary_function
{ };
// - a pointer to member function type (binary, volatile)
template
struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>
: binary_function
{ };
// - a pointer to member function type (unary, const volatile)
template
struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>
: unary_function
{ };
// - a pointer to member function type (binary, const volatile)
template
struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>
: binary_function
{ };
/// reference_wrapper
template
class reference_wrapper
: public _Reference_wrapper_base::type>
{
// If _Tp is a function type, we can't form result_of<_Tp(...)>,
// so turn it into a function pointer type.
typedef typename _Function_to_function_pointer<_Tp>::type
_M_func_type;
_Tp* _M_data;
public:
typedef _Tp type;
explicit
reference_wrapper(_Tp& __indata)
: _M_data(std::__addressof(__indata))
{ }
reference_wrapper(const reference_wrapper<_Tp>& __inref):
_M_data(__inref._M_data)
{ }
reference_wrapper&
operator=(const reference_wrapper<_Tp>& __inref)
{
_M_data = __inref._M_data;
return *this;
}
operator _Tp&() const
{ return this->get(); }
_Tp&
get() const
{ return *_M_data; }
template
typename result_of<_M_func_type(_Args...)>::type
operator()(_Args&... __args) const
{
return __invoke(get(), __args...);
}
};
// Denotes a reference should be taken to a variable.
template
inline reference_wrapper<_Tp>
ref(_Tp& __t)
{ return reference_wrapper<_Tp>(__t); }
// Denotes a const reference should be taken to a variable.
template
inline reference_wrapper
cref(const _Tp& __t)
{ return reference_wrapper(__t); }
template
inline reference_wrapper<_Tp>
ref(reference_wrapper<_Tp> __t)
{ return ref(__t.get()); }
template
inline reference_wrapper
cref(reference_wrapper<_Tp> __t)
{ return cref(__t.get()); }
template
struct _Mem_fn_const_or_non
{
typedef const _Tp& type;
};
template
struct _Mem_fn_const_or_non<_Tp, false>
{
typedef _Tp& type;
};
/**
* Derives from @c unary_function or @c binary_function, or perhaps
* nothing, depending on the number of arguments provided. The
* primary template is the basis case, which derives nothing.
*/
template
struct _Maybe_unary_or_binary_function { };
/// Derives from @c unary_function, as appropriate.
template
struct _Maybe_unary_or_binary_function<_Res, _T1>
: std::unary_function<_T1, _Res> { };
/// Derives from @c binary_function, as appropriate.
template
struct _Maybe_unary_or_binary_function<_Res, _T1, _T2>
: std::binary_function<_T1, _T2, _Res> { };
/// Implementation of @c mem_fn for member function pointers.
template
class _Mem_fn<_Res (_Class::*)(_ArgTypes...)>
: public _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>
{
typedef _Res (_Class::*_Functor)(_ArgTypes...);
template
_Res
_M_call(_Tp& __object, const volatile _Class *,
_ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
template
_Res
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
{ return ((*__ptr).*__pmf)(__args...); }
public:
typedef _Res result_type;
explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
// Handle objects
_Res
operator()(_Class& __object, _ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
// Handle pointers
_Res
operator()(_Class* __object, _ArgTypes... __args) const
{ return (__object->*__pmf)(__args...); }
// Handle smart pointers, references and pointers to derived
template
_Res
operator()(_Tp& __object, _ArgTypes... __args) const
{ return _M_call(__object, &__object, __args...); }
private:
_Functor __pmf;
};
/// Implementation of @c mem_fn for const member function pointers.
template
class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const>
: public _Maybe_unary_or_binary_function<_Res, const _Class*,
_ArgTypes...>
{
typedef _Res (_Class::*_Functor)(_ArgTypes...) const;
template
_Res
_M_call(_Tp& __object, const volatile _Class *,
_ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
template
_Res
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
{ return ((*__ptr).*__pmf)(__args...); }
public:
typedef _Res result_type;
explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
// Handle objects
_Res
operator()(const _Class& __object, _ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
// Handle pointers
_Res
operator()(const _Class* __object, _ArgTypes... __args) const
{ return (__object->*__pmf)(__args...); }
// Handle smart pointers, references and pointers to derived
template
_Res operator()(_Tp& __object, _ArgTypes... __args) const
{ return _M_call(__object, &__object, __args...); }
private:
_Functor __pmf;
};
/// Implementation of @c mem_fn for volatile member function pointers.
template
class _Mem_fn<_Res (_Class::*)(_ArgTypes...) volatile>
: public _Maybe_unary_or_binary_function<_Res, volatile _Class*,
_ArgTypes...>
{
typedef _Res (_Class::*_Functor)(_ArgTypes...) volatile;
template
_Res
_M_call(_Tp& __object, const volatile _Class *,
_ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
template
_Res
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
{ return ((*__ptr).*__pmf)(__args...); }
public:
typedef _Res result_type;
explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
// Handle objects
_Res
operator()(volatile _Class& __object, _ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
// Handle pointers
_Res
operator()(volatile _Class* __object, _ArgTypes... __args) const
{ return (__object->*__pmf)(__args...); }
// Handle smart pointers, references and pointers to derived
template
_Res
operator()(_Tp& __object, _ArgTypes... __args) const
{ return _M_call(__object, &__object, __args...); }
private:
_Functor __pmf;
};
/// Implementation of @c mem_fn for const volatile member function pointers.
template
class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const volatile>
: public _Maybe_unary_or_binary_function<_Res, const volatile _Class*,
_ArgTypes...>
{
typedef _Res (_Class::*_Functor)(_ArgTypes...) const volatile;
template
_Res
_M_call(_Tp& __object, const volatile _Class *,
_ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
template
_Res
_M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
{ return ((*__ptr).*__pmf)(__args...); }
public:
typedef _Res result_type;
explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
// Handle objects
_Res
operator()(const volatile _Class& __object, _ArgTypes... __args) const
{ return (__object.*__pmf)(__args...); }
// Handle pointers
_Res
operator()(const volatile _Class* __object, _ArgTypes... __args) const
{ return (__object->*__pmf)(__args...); }
// Handle smart pointers, references and pointers to derived
template
_Res operator()(_Tp& __object, _ArgTypes... __args) const
{ return _M_call(__object, &__object, __args...); }
private:
_Functor __pmf;
};
template
class _Mem_fn<_Res _Class::*>
{
// This bit of genius is due to Peter Dimov, improved slightly by
// Douglas Gregor.
template
_Res&
_M_call(_Tp& __object, _Class *) const
{ return __object.*__pm; }
template
_Res&
_M_call(_Tp& __object, _Up * const *) const
{ return (*__object).*__pm; }
template
const _Res&
_M_call(_Tp& __object, const _Up * const *) const
{ return (*__object).*__pm; }
template
const _Res&
_M_call(_Tp& __object, const _Class *) const
{ return __object.*__pm; }
template
const _Res&
_M_call(_Tp& __ptr, const volatile void*) const
{ return (*__ptr).*__pm; }
template static _Tp& __get_ref();
template
static __sfinae_types::__one __check_const(_Tp&, _Class*);
template
static __sfinae_types::__one __check_const(_Tp&, _Up * const *);
template
static __sfinae_types::__two __check_const(_Tp&, const _Up * const *);
template
static __sfinae_types::__two __check_const(_Tp&, const _Class*);
template
static __sfinae_types::__two __check_const(_Tp&, const volatile void*);
public:
template
struct _Result_type
: _Mem_fn_const_or_non<_Res,
(sizeof(__sfinae_types::__two)
== sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))>
{ };
template
struct result;
template
struct result<_CVMem(_Tp)>
: public _Result_type<_Tp> { };
template
struct result<_CVMem(_Tp&)>
: public _Result_type<_Tp> { };
explicit
_Mem_fn(_Res _Class::*__pm) : __pm(__pm) { }
// Handle objects
_Res&
operator()(_Class& __object) const
{ return __object.*__pm; }
const _Res&
operator()(const _Class& __object) const
{ return __object.*__pm; }
// Handle pointers
_Res&
operator()(_Class* __object) const
{ return __object->*__pm; }
const _Res&
operator()(const _Class* __object) const
{ return __object->*__pm; }
// Handle smart pointers and derived
template
typename _Result_type<_Tp>::type
operator()(_Tp& __unknown) const
{ return _M_call(__unknown, &__unknown); }
private:
_Res _Class::*__pm;
};
/**
* @brief Returns a function object that forwards to the member
* pointer @a pm.
*/
template
inline _Mem_fn<_Tp _Class::*>
mem_fn(_Tp _Class::* __pm)
{
return _Mem_fn<_Tp _Class::*>(__pm);
}
/**
* @brief Determines if the given type _Tp is a function object
* should be treated as a subexpression when evaluating calls to
* function objects returned by bind(). [TR1 3.6.1]
*/
template
struct is_bind_expression
{ static const bool value = false; };
template
const bool is_bind_expression<_Tp>::value;
/**
* @brief Determines if the given type _Tp is a placeholder in a
* bind() expression and, if so, which placeholder it is. [TR1 3.6.2]
*/
template
struct is_placeholder
{ static const int value = 0; };
template
const int is_placeholder<_Tp>::value;
/// The type of placeholder objects defined by libstdc++.
template struct _Placeholder { };
/** @namespace std::tr1::placeholders
* @brief Sub-namespace for tr1/functional.
*/
namespace placeholders
{
/* Define a large number of placeholders. There is no way to
* simplify this with variadic templates, because we're introducing
* unique names for each.
*/
namespace
{
_Placeholder<1> _1;
_Placeholder<2> _2;
_Placeholder<3> _3;
_Placeholder<4> _4;
_Placeholder<5> _5;
_Placeholder<6> _6;
_Placeholder<7> _7;
_Placeholder<8> _8;
_Placeholder<9> _9;
_Placeholder<10> _10;
_Placeholder<11> _11;
_Placeholder<12> _12;
_Placeholder<13> _13;
_Placeholder<14> _14;
_Placeholder<15> _15;
_Placeholder<16> _16;
_Placeholder<17> _17;
_Placeholder<18> _18;
_Placeholder<19> _19;
_Placeholder<20> _20;
_Placeholder<21> _21;
_Placeholder<22> _22;
_Placeholder<23> _23;
_Placeholder<24> _24;
_Placeholder<25> _25;
_Placeholder<26> _26;
_Placeholder<27> _27;
_Placeholder<28> _28;
_Placeholder<29> _29;
}
}
/**
* Partial specialization of is_placeholder that provides the placeholder
* number for the placeholder objects defined by libstdc++.
*/
template
struct is_placeholder<_Placeholder<_Num> >
{ static const int value = _Num; };
template
const int is_placeholder<_Placeholder<_Num> >::value;
#if __cplusplus >= 201103L
template
struct is_placeholder>
: std::integral_constant
{ };
template
struct is_placeholder>
: std::integral_constant
{ };
#endif
/**
* Stores a tuple of indices. Used by bind() to extract the elements
* in a tuple.
*/
template
struct _Index_tuple { };
/// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
template >
struct _Build_index_tuple;
template
struct _Build_index_tuple<_Num, _Index_tuple<_Indexes...> >
: _Build_index_tuple<_Num - 1,
_Index_tuple<_Indexes..., sizeof...(_Indexes)> >
{
};
template
struct _Build_index_tuple<0, _Index_tuple<_Indexes...> >
{
typedef _Index_tuple<_Indexes...> __type;
};
/**
* Used by _Safe_tuple_element to indicate that there is no tuple
* element at this position.
*/
struct _No_tuple_element;
/**
* Implementation helper for _Safe_tuple_element. This primary
* template handles the case where it is safe to use @c
* tuple_element.
*/
template
struct _Safe_tuple_element_impl
: tuple_element<__i, _Tuple> { };
/**
* Implementation helper for _Safe_tuple_element. This partial
* specialization handles the case where it is not safe to use @c
* tuple_element. We just return @c _No_tuple_element.
*/
template
struct _Safe_tuple_element_impl<__i, _Tuple, false>
{
typedef _No_tuple_element type;
};
/**
* Like tuple_element, but returns @c _No_tuple_element when
* tuple_element would return an error.
*/
template
struct _Safe_tuple_element
: _Safe_tuple_element_impl<__i, _Tuple,
(__i >= 0 && __i < tuple_size<_Tuple>::value)>
{
};
/**
* Maps an argument to bind() into an actual argument to the bound
* function object [TR1 3.6.3/5]. Only the first parameter should
* be specified: the rest are used to determine among the various
* implementations. Note that, although this class is a function
* object, it isn't entirely normal because it takes only two
* parameters regardless of the number of parameters passed to the
* bind expression. The first parameter is the bound argument and
* the second parameter is a tuple containing references to the
* rest of the arguments.
*/
template::value,
bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
class _Mu;
/**
* If the argument is reference_wrapper<_Tp>, returns the
* underlying reference. [TR1 3.6.3/5 bullet 1]
*/
template
class _Mu, false, false>
{
public:
typedef _Tp& result_type;
/* Note: This won't actually work for const volatile
* reference_wrappers, because reference_wrapper::get() is const
* but not volatile-qualified. This might be a defect in the TR.
*/
template
result_type
operator()(_CVRef& __arg, const _Tuple&) const volatile
{ return __arg.get(); }
};
/**
* If the argument is a bind expression, we invoke the underlying
* function object with the same cv-qualifiers as we are given and
* pass along all of our arguments (unwrapped). [TR1 3.6.3/5 bullet 2]
*/
template
class _Mu<_Arg, true, false>
{
public:
template class result;
// Determine the result type when we pass the arguments along. This
// involves passing along the cv-qualifiers placed on _Mu and
// unwrapping the argument bundle.
template
class result<_CVMu(_CVArg, tuple<_Args...>)>
: public result_of<_CVArg(_Args...)> { };
template
typename result_of<_CVArg(_Args...)>::type
operator()(_CVArg& __arg,
const tuple<_Args...>& __tuple) const volatile
{
// Construct an index tuple and forward to __call
typedef typename _Build_index_tuple::__type
_Indexes;
return this->__call(__arg, __tuple, _Indexes());
}
private:
// Invokes the underlying function object __arg by unpacking all
// of the arguments in the tuple.
template
typename result_of<_CVArg(_Args...)>::type
__call(_CVArg& __arg, const tuple<_Args...>& __tuple,
const _Index_tuple<_Indexes...>&) const volatile
{
return __arg(tr1::get<_Indexes>(__tuple)...);
}
};
/**
* If the argument is a placeholder for the Nth argument, returns
* a reference to the Nth argument to the bind function object.
* [TR1 3.6.3/5 bullet 3]
*/
template
class _Mu<_Arg, false, true>
{
public:
template class result;
template
class result<_CVMu(_CVArg, _Tuple)>
{
// Add a reference, if it hasn't already been done for us.
// This allows us to be a little bit sloppy in constructing
// the tuple that we pass to result_of<...>.
typedef typename _Safe_tuple_element<(is_placeholder<_Arg>::value
- 1), _Tuple>::type
__base_type;
public:
typedef typename add_reference<__base_type>::type type;
};
template
typename result<_Mu(_Arg, _Tuple)>::type
operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile
{
return ::std::tr1::get<(is_placeholder<_Arg>::value - 1)>(__tuple);
}
};
/**
* If the argument is just a value, returns a reference to that
* value. The cv-qualifiers on the reference are the same as the
* cv-qualifiers on the _Mu object. [TR1 3.6.3/5 bullet 4]
*/
template
class _Mu<_Arg, false, false>
{
public:
template struct result;
template
struct result<_CVMu(_CVArg, _Tuple)>
{
typedef typename add_reference<_CVArg>::type type;
};
// Pick up the cv-qualifiers of the argument
template
_CVArg&
operator()(_CVArg& __arg, const _Tuple&) const volatile
{ return __arg; }
};
/**
* Maps member pointers into instances of _Mem_fn but leaves all
* other function objects untouched. Used by tr1::bind(). The
* primary template handles the non--member-pointer case.
*/
template
struct _Maybe_wrap_member_pointer
{
typedef _Tp type;
static const _Tp&
__do_wrap(const _Tp& __x)
{ return __x; }
};
/**
* Maps member pointers into instances of _Mem_fn but leaves all
* other function objects untouched. Used by tr1::bind(). This
* partial specialization handles the member pointer case.
*/
template
struct _Maybe_wrap_member_pointer<_Tp _Class::*>
{
typedef _Mem_fn<_Tp _Class::*> type;
static type
__do_wrap(_Tp _Class::* __pm)
{ return type(__pm); }
};
/// Type of the function object returned from bind().
template
struct _Bind;
template
class _Bind<_Functor(_Bound_args...)>
: public _Weak_result_type<_Functor>
{
typedef _Bind __self_type;
typedef typename _Build_index_tuple::__type
_Bound_indexes;
_Functor _M_f;
tuple<_Bound_args...> _M_bound_args;
// Call unqualified
template
typename result_of<
_Functor(typename result_of<_Mu<_Bound_args>
(_Bound_args, tuple<_Args...>)>::type...)
>::type
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>)
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
// Call as const
template
typename result_of<
const _Functor(typename result_of<_Mu<_Bound_args>
(const _Bound_args, tuple<_Args...>)
>::type...)>::type
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
// Call as volatile
template
typename result_of<
volatile _Functor(typename result_of<_Mu<_Bound_args>
(volatile _Bound_args, tuple<_Args...>)
>::type...)>::type
__call(const tuple<_Args...>& __args,
_Index_tuple<_Indexes...>) volatile
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
// Call as const volatile
template
typename result_of<
const volatile _Functor(typename result_of<_Mu<_Bound_args>
(const volatile _Bound_args,
tuple<_Args...>)
>::type...)>::type
__call(const tuple<_Args...>& __args,
_Index_tuple<_Indexes...>) const volatile
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
public:
explicit _Bind(_Functor __f, _Bound_args... __bound_args)
: _M_f(__f), _M_bound_args(__bound_args...) { }
// Call unqualified
template
typename result_of<
_Functor(typename result_of<_Mu<_Bound_args>
(_Bound_args, tuple<_Args...>)>::type...)
>::type
operator()(_Args&... __args)
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
// Call as const
template
typename result_of<
const _Functor(typename result_of<_Mu<_Bound_args>
(const _Bound_args, tuple<_Args...>)>::type...)
>::type
operator()(_Args&... __args) const
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
// Call as volatile
template
typename result_of<
volatile _Functor(typename result_of<_Mu<_Bound_args>
(volatile _Bound_args, tuple<_Args...>)>::type...)
>::type
operator()(_Args&... __args) volatile
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
// Call as const volatile
template
typename result_of<
const volatile _Functor(typename result_of<_Mu<_Bound_args>
(const volatile _Bound_args,
tuple<_Args...>)>::type...)
>::type
operator()(_Args&... __args) const volatile
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
};
/// Type of the function object returned from bind().
template
struct _Bind_result;
template
class _Bind_result<_Result, _Functor(_Bound_args...)>
{
typedef _Bind_result __self_type;
typedef typename _Build_index_tuple::__type
_Bound_indexes;
_Functor _M_f;
tuple<_Bound_args...> _M_bound_args;
// Call unqualified
template
_Result
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>)
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
// Call as const
template
_Result
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
// Call as volatile
template
_Result
__call(const tuple<_Args...>& __args,
_Index_tuple<_Indexes...>) volatile
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
// Call as const volatile
template
_Result
__call(const tuple<_Args...>& __args,
_Index_tuple<_Indexes...>) const volatile
{
return _M_f(_Mu<_Bound_args>()
(tr1::get<_Indexes>(_M_bound_args), __args)...);
}
public:
typedef _Result result_type;
explicit
_Bind_result(_Functor __f, _Bound_args... __bound_args)
: _M_f(__f), _M_bound_args(__bound_args...) { }
// Call unqualified
template
result_type
operator()(_Args&... __args)
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
// Call as const
template
result_type
operator()(_Args&... __args) const
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
// Call as volatile
template
result_type
operator()(_Args&... __args) volatile
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
// Call as const volatile
template
result_type
operator()(_Args&... __args) const volatile
{
return this->__call(tr1::tie(__args...), _Bound_indexes());
}
};
/// Class template _Bind is always a bind expression.
template
struct is_bind_expression<_Bind<_Signature> >
{ static const bool value = true; };
template
const bool is_bind_expression<_Bind<_Signature> >::value;
/// Class template _Bind is always a bind expression.
template
struct is_bind_expression >
{ static const bool value = true; };
template
const bool is_bind_expression >::value;
/// Class template _Bind is always a bind expression.
template
struct is_bind_expression >
{ static const bool value = true; };
template
const bool is_bind_expression >::value;
/// Class template _Bind is always a bind expression.
template
struct is_bind_expression >
{ static const bool value = true; };
template
const bool is_bind_expression >::value;
/// Class template _Bind_result is always a bind expression.
template
struct is_bind_expression<_Bind_result<_Result, _Signature> >
{ static const bool value = true; };
template
const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value;
/// Class template _Bind_result is always a bind expression.
template
struct is_bind_expression >
{ static const bool value = true; };
template
const bool
is_bind_expression >::value;
/// Class template _Bind_result is always a bind expression.
template
struct is_bind_expression >
{ static const bool value = true; };
template
const bool
is_bind_expression >::value;
/// Class template _Bind_result is always a bind expression.
template
struct
is_bind_expression >
{ static const bool value = true; };
template
const bool
is_bind_expression >::value;
#if __cplusplus >= 201103L
template
struct is_bind_expression>
: true_type { };
template
struct is_bind_expression>
: true_type { };
template
struct is_bind_expression>
: true_type { };
template
struct is_bind_expression>
: true_type { };
template
struct is_bind_expression>
: true_type { };
template
struct is_bind_expression>
: true_type { };
template
struct is_bind_expression>
: true_type { };
template
struct is_bind_expression>
: true_type { };
#endif
/// bind
template
inline
_Bind::type(_ArgTypes...)>
bind(_Functor __f, _ArgTypes... __args)
{
typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
typedef typename __maybe_type::type __functor_type;
typedef _Bind<__functor_type(_ArgTypes...)> __result_type;
return __result_type(__maybe_type::__do_wrap(__f), __args...);
}
template
inline
_Bind_result<_Result,
typename _Maybe_wrap_member_pointer<_Functor>::type
(_ArgTypes...)>
bind(_Functor __f, _ArgTypes... __args)
{
typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
typedef typename __maybe_type::type __functor_type;
typedef _Bind_result<_Result, __functor_type(_ArgTypes...)>
__result_type;
return __result_type(__maybe_type::__do_wrap(__f), __args...);
}
/**
* @brief Exception class thrown when class template function's
* operator() is called with an empty target.
* @ingroup exceptions
*/
class bad_function_call : public std::exception { };
/**
* The integral constant expression 0 can be converted into a
* pointer to this type. It is used by the function template to
* accept NULL pointers.
*/
struct _M_clear_type;
/**
* Trait identifying @a location-invariant types, meaning that the
* address of the object (or any of its members) will not escape.
* Also implies a trivial copy constructor and assignment operator.
*/
template
struct __is_location_invariant
: integral_constant::value
|| is_member_pointer<_Tp>::value)>
{
};
class _Undefined_class;
union _Nocopy_types
{
void* _M_object;
const void* _M_const_object;
void (*_M_function_pointer)();
void (_Undefined_class::*_M_member_pointer)();
};
union _Any_data
{
void* _M_access() { return &_M_pod_data[0]; }
const void* _M_access() const { return &_M_pod_data[0]; }
template
_Tp&
_M_access()
{ return *static_cast<_Tp*>(_M_access()); }
template
const _Tp&
_M_access() const
{ return *static_cast