Installed allocator into std::function

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@111672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2010-08-20 19:36:46 +00:00
parent e00e030f58
commit 725528086c
9 changed files with 739 additions and 145 deletions

View File

@@ -367,7 +367,7 @@ template<class _F, class _Alloc, class _R>
_R
__func<_F, _Alloc, _R()>::operator()()
{
return __invoke<_R>(__f_.first());
return __invoke(__f_.first());
}
#ifndef _LIBCPP_NO_RTTI
@@ -660,16 +660,15 @@ public:
function(_F,
typename enable_if<!is_integral<_F>::value>::type* = 0);
// template<class _Alloc>
// function(allocator_arg_t, const _Alloc&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, nullptr_t);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, const function&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, function&&);
// template<class F, Allocator Alloc>
// function(allocator_arg_t, const Alloc&, F);
template<class _Alloc>
function(allocator_arg_t, const _Alloc&) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, const function&);
template<class _F, class _Alloc>
function(allocator_arg_t, const _Alloc& __a, _F __f,
typename enable_if<!is_integral<_F>::value>::type* = 0);
function& operator=(const function&);
function& operator=(nullptr_t);
@@ -685,8 +684,9 @@ public:
// 20.7.16.2.2, function modifiers:
void swap(function&);
// template<class _F, class _Alloc>
// void assign(_F, const _Alloc&);
template<class _F, class _Alloc>
void assign(_F __f, const _Alloc& __a)
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
operator bool() const {return __f_;}
@@ -723,6 +723,21 @@ function<_R()>::function(const function& __f)
__f_ = __f.__f_->__clone();
}
template<class _R>
template<class _Alloc>
function<_R()>::function(allocator_arg_t, const _Alloc&, const function& __f)
{
if (__f.__f_ == 0)
__f_ = 0;
else if (__f.__f_ == (const __base*)&__f.__buf_)
{
__f_ = (__base*)&__buf_;
__f.__f_->__clone(__f_);
}
else
__f_ = __f.__f_->__clone();
}
template<class _R>
template <class _F>
function<_R()>::function(_F __f,
@@ -749,6 +764,39 @@ function<_R()>::function(_F __f,
}
}
template<class _R>
template <class _F, class _Alloc>
function<_R()>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
typename enable_if<!is_integral<_F>::value>::type*)
: __f_(0)
{
typedef allocator_traits<_Alloc> __alloc_traits;
if (__not_null(__f))
{
typedef __function::__func<_F, _Alloc, _R()> _FF;
if (sizeof(_FF) <= sizeof(__buf_))
{
__f_ = (__base*)&__buf_;
::new (__f_) _FF(__f);
}
else
{
typedef typename __alloc_traits::template
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
rebind_alloc<_FF>
#else
rebind_alloc<_FF>::other
#endif
_A;
_A __a(__a0);
typedef __allocator_destructor<_A> _D;
unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
::new (__hold.get()) _FF(__f, _Alloc(__a));
__f_ = __hold.release();
}
}
}
template<class _R>
function<_R()>&
function<_R()>::operator=(const function& __f)
@@ -904,16 +952,15 @@ public:
function(_F,
typename enable_if<!is_integral<_F>::value>::type* = 0);
// template<class _Alloc>
// function(allocator_arg_t, const _Alloc&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, nullptr_t);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, const function&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, function&&);
// template<class F, Allocator Alloc>
// function(allocator_arg_t, const Alloc&, F);
template<class _Alloc>
function(allocator_arg_t, const _Alloc&) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, const function&);
template<class _F, class _Alloc>
function(allocator_arg_t, const _Alloc& __a, _F __f,
typename enable_if<!is_integral<_F>::value>::type* = 0);
function& operator=(const function&);
function& operator=(nullptr_t);
@@ -929,8 +976,9 @@ public:
// 20.7.16.2.2, function modifiers:
void swap(function&);
// template<class _F, class _Alloc>
// void assign(_F, const _Alloc&);
template<class _F, class _Alloc>
void assign(_F __f, const _Alloc& __a)
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
operator bool() const {return __f_;}
@@ -967,6 +1015,21 @@ function<_R(_A0)>::function(const function& __f)
__f_ = __f.__f_->__clone();
}
template<class _R, class _A0>
template<class _Alloc>
function<_R(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f)
{
if (__f.__f_ == 0)
__f_ = 0;
else if (__f.__f_ == (const __base*)&__f.__buf_)
{
__f_ = (__base*)&__buf_;
__f.__f_->__clone(__f_);
}
else
__f_ = __f.__f_->__clone();
}
template<class _R, class _A0>
template <class _F>
function<_R(_A0)>::function(_F __f,
@@ -993,6 +1056,39 @@ function<_R(_A0)>::function(_F __f,
}
}
template<class _R, class _A0>
template <class _F, class _Alloc>
function<_R(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
typename enable_if<!is_integral<_F>::value>::type*)
: __f_(0)
{
typedef allocator_traits<_Alloc> __alloc_traits;
if (__not_null(__f))
{
typedef __function::__func<_F, _Alloc, _R(_A0)> _FF;
if (sizeof(_FF) <= sizeof(__buf_))
{
__f_ = (__base*)&__buf_;
::new (__f_) _FF(__f);
}
else
{
typedef typename __alloc_traits::template
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
rebind_alloc<_FF>
#else
rebind_alloc<_FF>::other
#endif
_A;
_A __a(__a0);
typedef __allocator_destructor<_A> _D;
unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
::new (__hold.get()) _FF(__f, _Alloc(__a));
__f_ = __hold.release();
}
}
}
template<class _R, class _A0>
function<_R(_A0)>&
function<_R(_A0)>::operator=(const function& __f)
@@ -1148,16 +1244,15 @@ public:
function(_F,
typename enable_if<!is_integral<_F>::value>::type* = 0);
// template<class _Alloc>
// function(allocator_arg_t, const _Alloc&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, nullptr_t);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, const function&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, function&&);
// template<class F, Allocator Alloc>
// function(allocator_arg_t, const Alloc&, F);
template<class _Alloc>
function(allocator_arg_t, const _Alloc&) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, const function&);
template<class _F, class _Alloc>
function(allocator_arg_t, const _Alloc& __a, _F __f,
typename enable_if<!is_integral<_F>::value>::type* = 0);
function& operator=(const function&);
function& operator=(nullptr_t);
@@ -1173,8 +1268,9 @@ public:
// 20.7.16.2.2, function modifiers:
void swap(function&);
// template<class _F, class _Alloc>
// void assign(_F, const _Alloc&);
template<class _F, class _Alloc>
void assign(_F __f, const _Alloc& __a)
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
operator bool() const {return __f_;}
@@ -1211,10 +1307,25 @@ function<_R(_A0, _A1)>::function(const function& __f)
__f_ = __f.__f_->__clone();
}
template<class _R, class _A0, class _A1>
template<class _Alloc>
function<_R(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f)
{
if (__f.__f_ == 0)
__f_ = 0;
else if (__f.__f_ == (const __base*)&__f.__buf_)
{
__f_ = (__base*)&__buf_;
__f.__f_->__clone(__f_);
}
else
__f_ = __f.__f_->__clone();
}
template<class _R, class _A0, class _A1>
template <class _F>
function<_R(_A0, _A1)>::function(_F __f,
typename enable_if<!is_integral<_F>::value>::type*)
typename enable_if<!is_integral<_F>::value>::type*)
: __f_(0)
{
if (__not_null(__f))
@@ -1237,6 +1348,39 @@ function<_R(_A0, _A1)>::function(_F __f,
}
}
template<class _R, class _A0, class _A1>
template <class _F, class _Alloc>
function<_R(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
typename enable_if<!is_integral<_F>::value>::type*)
: __f_(0)
{
typedef allocator_traits<_Alloc> __alloc_traits;
if (__not_null(__f))
{
typedef __function::__func<_F, _Alloc, _R(_A0, _A1)> _FF;
if (sizeof(_FF) <= sizeof(__buf_))
{
__f_ = (__base*)&__buf_;
::new (__f_) _FF(__f);
}
else
{
typedef typename __alloc_traits::template
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
rebind_alloc<_FF>
#else
rebind_alloc<_FF>::other
#endif
_A;
_A __a(__a0);
typedef __allocator_destructor<_A> _D;
unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
::new (__hold.get()) _FF(__f, _Alloc(__a));
__f_ = __hold.release();
}
}
}
template<class _R, class _A0, class _A1>
function<_R(_A0, _A1)>&
function<_R(_A0, _A1)>::operator=(const function& __f)
@@ -1391,16 +1535,15 @@ public:
function(_F,
typename enable_if<!is_integral<_F>::value>::type* = 0);
// template<class _Alloc>
// function(allocator_arg_t, const _Alloc&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, nullptr_t);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, const function&);
// template<Allocator Alloc>
// function(allocator_arg_t, const Alloc&, function&&);
// template<class F, Allocator Alloc>
// function(allocator_arg_t, const Alloc&, F);
template<class _Alloc>
function(allocator_arg_t, const _Alloc&) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, const function&);
template<class _F, class _Alloc>
function(allocator_arg_t, const _Alloc& __a, _F __f,
typename enable_if<!is_integral<_F>::value>::type* = 0);
function& operator=(const function&);
function& operator=(nullptr_t);
@@ -1416,8 +1559,9 @@ public:
// 20.7.16.2.2, function modifiers:
void swap(function&);
// template<class _F, class _Alloc>
// void assign(_F, const _Alloc&);
template<class _F, class _Alloc>
void assign(_F __f, const _Alloc& __a)
{function(allocator_arg, __a, __f).swap(*this);}
// 20.7.16.2.3, function capacity:
operator bool() const {return __f_;}
@@ -1454,6 +1598,22 @@ function<_R(_A0, _A1, _A2)>::function(const function& __f)
__f_ = __f.__f_->__clone();
}
template<class _R, class _A0, class _A1, class _A2>
template<class _Alloc>
function<_R(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&,
const function& __f)
{
if (__f.__f_ == 0)
__f_ = 0;
else if (__f.__f_ == (const __base*)&__f.__buf_)
{
__f_ = (__base*)&__buf_;
__f.__f_->__clone(__f_);
}
else
__f_ = __f.__f_->__clone();
}
template<class _R, class _A0, class _A1, class _A2>
template <class _F>
function<_R(_A0, _A1, _A2)>::function(_F __f,
@@ -1480,6 +1640,39 @@ function<_R(_A0, _A1, _A2)>::function(_F __f,
}
}
template<class _R, class _A0, class _A1, class _A2>
template <class _F, class _Alloc>
function<_R(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
typename enable_if<!is_integral<_F>::value>::type*)
: __f_(0)
{
typedef allocator_traits<_Alloc> __alloc_traits;
if (__not_null(__f))
{
typedef __function::__func<_F, _Alloc, _R(_A0, _A1, _A2)> _FF;
if (sizeof(_FF) <= sizeof(__buf_))
{
__f_ = (__base*)&__buf_;
::new (__f_) _FF(__f);
}
else
{
typedef typename __alloc_traits::template
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
rebind_alloc<_FF>
#else
rebind_alloc<_FF>::other
#endif
_A;
_A __a(__a0);
typedef __allocator_destructor<_A> _D;
unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
::new (__hold.get()) _FF(__f, _Alloc(__a));
__f_ = __hold.release();
}
}
}
template<class _R, class _A0, class _A1, class _A2>
function<_R(_A0, _A1, _A2)>&
function<_R(_A0, _A1, _A2)>::operator=(const function& __f)