Commit d90d97ff by Jonathan Wakely Committed by Jonathan Wakely

re PR libstdc++/24803 ([c++0x] reference_wrapper and pointers to member functions)

2010-01-12  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/24803
	PR libstdc++/35569
	PR libstdc++/42593
	* include/std/functional (bind): Forward rvalues and detect correct
	result type of bound function object.
	* include/std/mutex (call_once): Specify bind result type.
	* testsuite/20_util/reference_wrapper/invoke.cc: Remove invalid tests.
	* testsuite/20_util/reference_wrapper/24803.cc: Remove invalid tests
	and enable FIXME tests.
	* testsuite/20_util/bind/35569.cc: New.
	* testsuite/20_util/bind/ref2.cc: New.
	* testsuite/20_util/bind/38889.cc: New.
	* testsuite/20_util/bind/ref_neg.cc: New.
	* testsuite/20_util/bind/42593.cc: New.

From-SVN: r155826
parent 31380bc4
2010-01-12 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/24803
PR libstdc++/35569
PR libstdc++/42593
* include/std/functional (bind): Forward rvalues and detect correct
result type of bound function object.
* include/std/mutex (call_once): Specify bind result type.
* testsuite/20_util/reference_wrapper/invoke.cc: Remove invalid tests.
* testsuite/20_util/reference_wrapper/24803.cc: Remove invalid tests
and enable FIXME tests.
* testsuite/20_util/bind/35569.cc: New.
* testsuite/20_util/bind/ref2.cc: New.
* testsuite/20_util/bind/38889.cc: New.
* testsuite/20_util/bind/ref_neg.cc: New.
* testsuite/20_util/bind/42593.cc: New.
2010-01-11 Paolo Carlini <paolo.carlini@oracle.com>
* include/parallel/base.h (decode2): Rename to __decode2.
......
// <functional> -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -177,61 +177,12 @@ namespace std
template<typename _Signature>
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<bool _Has_result_type, typename _Signature>
struct _Result_of_impl;
// Handle member data pointers using _Mem_fn's logic
template<typename _Res, typename _Class, typename _T1>
struct _Result_of_impl<false, _Res _Class::*(_T1)>
{
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<typename _Functor, typename... _ArgTypes>
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<typename _Functor, typename... _ArgTypes>
struct _Result_of_impl<true, _Functor(_ArgTypes...)>
struct result_of<_Functor(_ArgTypes...)>
{
typedef typename _Weak_result_type<_Functor>::result_type type;
};
/**
* We need to compute the result type for this invocation the hard
* way.
*/
template<typename _Functor, typename... _ArgTypes>
struct _Result_of_impl<false, _Functor(_ArgTypes...)>
{
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<typename _Functor>
struct _Result_of_impl<false, _Functor()>
{
typedef void type;
typedef
decltype( std::declval<_Functor>()(std::declval<_ArgTypes>()...) )
type;
};
/// Determines if the type _Tp derives from unary_function.
......@@ -291,22 +242,9 @@ namespace std
&& !is_function<typename remove_pointer<_Functor>::type>::value),
typename result_of<_Functor(_Args...)>::type
>::__type
__invoke(_Functor& __f, _Args&... __args)
{
return __f(__args...);
}
template<typename _Functor, typename... _Args>
inline
typename __gnu_cxx::__enable_if<
(is_member_pointer<_Functor>::value
&& !is_function<_Functor>::value
&& !is_function<typename remove_pointer<_Functor>::type>::value),
typename result_of<_Functor(_Args...)>::type
>::__type
__invoke(_Functor& __f, _Args&... __args)
__invoke(_Functor& __f, _Args&&... __args)
{
return mem_fn(__f)(__args...);
return __f(std::forward<_Args>(__args)...);
}
// To pick up function references (that will become function pointers)
......@@ -317,9 +255,9 @@ namespace std
&& is_function<typename remove_pointer<_Functor>::type>::value),
typename result_of<_Functor(_Args...)>::type
>::__type
__invoke(_Functor __f, _Args&... __args)
__invoke(_Functor __f, _Args&&... __args)
{
return __f(__args...);
return __f(std::forward<_Args>(__args)...);
}
/**
......@@ -464,10 +402,11 @@ namespace std
public:
typedef _Tp type;
explicit
reference_wrapper(_Tp& __indata): _M_data(&__indata)
{ }
reference_wrapper(_Tp&&) = delete;
reference_wrapper(const reference_wrapper<_Tp>& __inref):
_M_data(__inref._M_data)
{ }
......@@ -488,9 +427,9 @@ namespace std
template<typename... _Args>
typename result_of<_M_func_type(_Args...)>::type
operator()(_Args&... __args) const
operator()(_Args&&... __args) const
{
return __invoke(get(), __args...);
return __invoke(get(), std::forward<_Args>(__args)...);
}
};
......@@ -1023,7 +962,7 @@ namespace std
template<typename _CVArg, typename... _Args>
typename result_of<_CVArg(_Args...)>::type
operator()(_CVArg& __arg,
const tuple<_Args...>& __tuple) const volatile
tuple<_Args...>& __tuple) const volatile
{
// Construct an index tuple and forward to __call
typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
......@@ -1036,10 +975,10 @@ namespace std
// of the arguments in the tuple.
template<typename _CVArg, typename... _Args, int... _Indexes>
typename result_of<_CVArg(_Args...)>::type
__call(_CVArg& __arg, const tuple<_Args...>& __tuple,
__call(_CVArg& __arg, tuple<_Args...>& __tuple,
const _Index_tuple<_Indexes...>&) const volatile
{
return __arg(get<_Indexes>(__tuple)...);
return __arg(std::forward<_Args>(get<_Indexes>(__tuple))...);
}
};
......@@ -1065,14 +1004,15 @@ namespace std
__base_type;
public:
typedef typename add_lvalue_reference<__base_type>::type type;
typedef typename add_rvalue_reference<__base_type>::type type;
};
template<typename _Tuple>
typename result<_Mu(_Arg, _Tuple)>::type
operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile
operator()(const volatile _Arg&, _Tuple& __tuple) const volatile
{
return ::std::get<(is_placeholder<_Arg>::value - 1)>(__tuple);
return std::forward<typename result<_Mu(_Arg, _Tuple)>::type>(
::std::get<(is_placeholder<_Arg>::value - 1)>(__tuple));
}
};
......@@ -1095,9 +1035,9 @@ namespace std
// Pick up the cv-qualifiers of the argument
template<typename _CVArg, typename _Tuple>
_CVArg&
operator()(_CVArg& __arg, const _Tuple&) const volatile
{ return __arg; }
_CVArg&&
operator()(_CVArg&& __arg, const _Tuple&) const volatile
{ return std::forward<_CVArg>(__arg); }
};
/**
......@@ -1156,36 +1096,46 @@ namespace std
tuple<_Bound_args...> _M_bound_args;
// Call unqualified
template<typename... _Args, int... _Indexes>
template<typename... _Args, int... _Indexes, typename _Sfinae
= decltype( std::declval<_Functor>()(
_Mu<_Bound_args>()( std::declval<_Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
_Functor(typename result_of<_Mu<_Bound_args>
(_Bound_args, tuple<_Args...>)>::type...)
(_Bound_args&, tuple<_Args...>&)>::type...)
>::type
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>)
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>)
{
return _M_f(_Mu<_Bound_args>()
(get<_Indexes>(_M_bound_args), __args)...);
}
// Call as const
template<typename... _Args, int... _Indexes>
template<typename... _Args, int... _Indexes, typename _Sfinae
= decltype( std::declval<const _Functor>()(
_Mu<_Bound_args>()( std::declval<const _Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
const _Functor(typename result_of<_Mu<_Bound_args>
(const _Bound_args, tuple<_Args...>)
(const _Bound_args&, tuple<_Args...>&)
>::type...)>::type
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>) const
{
return _M_f(_Mu<_Bound_args>()
(get<_Indexes>(_M_bound_args), __args)...);
}
#if 0
// Call as volatile
template<typename... _Args, int... _Indexes>
template<typename... _Args, int... _Indexes, typename _Sfinae
= decltype( std::declval<volatile _Functor>()(
_Mu<_Bound_args>()( std::declval<volatile _Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
volatile _Functor(typename result_of<_Mu<_Bound_args>
(volatile _Bound_args, tuple<_Args...>)
(volatile _Bound_args&, tuple<_Args...>&)
>::type...)>::type
__call(const tuple<_Args...>& __args,
__call(tuple<_Args...>&& __args,
_Index_tuple<_Indexes...>) volatile
{
return _M_f(_Mu<_Bound_args>()
......@@ -1193,69 +1143,92 @@ namespace std
}
// Call as const volatile
template<typename... _Args, int... _Indexes>
template<typename... _Args, int... _Indexes, typename _Sfinae
= decltype( std::declval<const volatile _Functor>()(
_Mu<_Bound_args>()( std::declval<const volatile _Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
const volatile _Functor(typename result_of<_Mu<_Bound_args>
(const volatile _Bound_args,
tuple<_Args...>)
(const volatile _Bound_args&,
tuple<_Args...>&)
>::type...)>::type
__call(const tuple<_Args...>& __args,
__call(tuple<_Args...>&& __args,
_Index_tuple<_Indexes...>) const volatile
{
return _M_f(_Mu<_Bound_args>()
(get<_Indexes>(_M_bound_args), __args)...);
}
#endif
public:
explicit _Bind(_Functor __f, _Bound_args... __bound_args)
: _M_f(__f), _M_bound_args(__bound_args...) { }
: _M_f(std::forward<_Functor>(__f)),
_M_bound_args(std::forward<_Bound_args>(__bound_args)...)
{ }
// Call unqualified
template<typename... _Args>
template<typename... _Args, typename _Sfinae
= decltype( std::declval<_Functor>()(
_Mu<_Bound_args>()( std::declval<_Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
_Functor(typename result_of<_Mu<_Bound_args>
(_Bound_args, tuple<_Args...>)>::type...)
(_Bound_args&, tuple<_Args...>&)>::type...)
>::type
operator()(_Args&... __args)
operator()(_Args&&... __args)
{
return this->__call(tie(__args...), _Bound_indexes());
return this->__call(tuple<_Args...>(std::forward<_Args>(__args)...),
_Bound_indexes());
}
// Call as const
template<typename... _Args>
template<typename... _Args, typename _Sfinae
= decltype( std::declval<const _Functor>()(
_Mu<_Bound_args>()( std::declval<const _Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
const _Functor(typename result_of<_Mu<_Bound_args>
(const _Bound_args, tuple<_Args...>)>::type...)
(const _Bound_args&, tuple<_Args...>&)>::type...)
>::type
operator()(_Args&... __args) const
operator()(_Args&&... __args) const
{
return this->__call(tie(__args...), _Bound_indexes());
return this->__call(tuple<_Args...>(std::forward<_Args>(__args)...),
_Bound_indexes());
}
#if 0
// Call as volatile
template<typename... _Args>
template<typename... _Args, typename _Sfinae
= decltype( std::declval<volatile _Functor>()(
_Mu<_Bound_args>()( std::declval<volatile _Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
volatile _Functor(typename result_of<_Mu<_Bound_args>
(volatile _Bound_args, tuple<_Args...>)>::type...)
(volatile _Bound_args&, tuple<_Args...>&)>::type...)
>::type
operator()(_Args&... __args) volatile
operator()(_Args&&... __args) volatile
{
return this->__call(tie(__args...), _Bound_indexes());
return this->__call(tuple<_Args...>(std::forward<_Args>(__args)...),
_Bound_indexes());
}
// Call as const volatile
template<typename... _Args>
template<typename... _Args, typename _Sfinae
= decltype( std::declval<const volatile _Functor>()(
_Mu<_Bound_args>()( std::declval<const volatile _Bound_args&>(),
std::declval<tuple<_Args...>&>() )... ) )>
typename result_of<
const volatile _Functor(typename result_of<_Mu<_Bound_args>
(const volatile _Bound_args,
tuple<_Args...>)>::type...)
(const volatile _Bound_args&,
tuple<_Args...>&)>::type...)
>::type
operator()(_Args&... __args) const volatile
operator()(_Args&&... __args) const volatile
{
return this->__call(tie(__args...), _Bound_indexes());
return this->__call(tuple<_Args...>(std::forward<_Args>(__args)...),
_Bound_indexes());
}
#endif
};
/// Type of the function object returned from bind<R>().
......@@ -1281,7 +1254,7 @@ namespace std
// Call unqualified
template<typename _Res, typename... _Args, int... _Indexes>
_Result
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>,
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
typename __disable_if_void<_Res>::type = 0)
{
return _M_f(_Mu<_Bound_args>()
......@@ -1291,7 +1264,7 @@ namespace std
// Call unqualified, return void
template<typename _Res, typename... _Args, int... _Indexes>
void
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>,
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
typename __enable_if_void<_Res>::type = 0)
{
_M_f(_Mu<_Bound_args>()
......@@ -1301,7 +1274,7 @@ namespace std
// Call as const
template<typename _Res, typename... _Args, int... _Indexes>
_Result
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>,
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
typename __disable_if_void<_Res>::type = 0) const
{
return _M_f(_Mu<_Bound_args>()
......@@ -1311,7 +1284,7 @@ namespace std
// Call as const, return void
template<typename _Res, typename... _Args, int... _Indexes>
void
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>,
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
typename __enable_if_void<_Res>::type = 0) const
{
_M_f(_Mu<_Bound_args>()
......@@ -1321,7 +1294,7 @@ namespace std
// Call as volatile
template<typename _Res, typename... _Args, int... _Indexes>
_Result
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>,
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
typename __disable_if_void<_Res>::type = 0) volatile
{
return _M_f(_Mu<_Bound_args>()
......@@ -1331,7 +1304,7 @@ namespace std
// Call as volatile, return void
template<typename _Res, typename... _Args, int... _Indexes>
void
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>,
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
typename __enable_if_void<_Res>::type = 0) volatile
{
_M_f(_Mu<_Bound_args>()
......@@ -1341,7 +1314,7 @@ namespace std
// Call as const volatile
template<typename _Res, typename... _Args, int... _Indexes>
_Result
__call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>,
__call(tuple<_Args...>&& __args, _Index_tuple<_Indexes...>,
typename __disable_if_void<_Res>::type = 0) const volatile
{
return _M_f(_Mu<_Bound_args>()
......@@ -1351,7 +1324,7 @@ namespace std
// Call as const volatile, return void
template<typename _Res, typename... _Args, int... _Indexes>
void
__call(const tuple<_Args...>& __args,
__call(tuple<_Args...>&& __args,
_Index_tuple<_Indexes...>,
typename __enable_if_void<_Res>::type = 0) const volatile
{
......@@ -1364,38 +1337,48 @@ namespace std
explicit
_Bind_result(_Functor __f, _Bound_args... __bound_args)
: _M_f(__f), _M_bound_args(__bound_args...) { }
: _M_f(std::forward<_Functor>(__f)),
_M_bound_args(std::forward<_Bound_args>(__bound_args)...)
{ }
// Call unqualified
template<typename... _Args>
result_type
operator()(_Args&... __args)
operator()(_Args&&... __args)
{
return this->__call<_Result>(tie(__args...), _Bound_indexes());
return this->__call<_Result>(
tuple<_Args...>(std::forward<_Args...>(__args)...),
_Bound_indexes());
}
// Call as const
template<typename... _Args>
result_type
operator()(_Args&... __args) const
operator()(_Args&&... __args) const
{
return this->__call<_Result>(tie(__args...), _Bound_indexes());
return this->__call<_Result>(
tuple<_Args...>(std::forward<_Args...>(__args)...),
_Bound_indexes());
}
// Call as volatile
template<typename... _Args>
result_type
operator()(_Args&... __args) volatile
operator()(_Args&&... __args) volatile
{
return this->__call<_Result>(tie(__args...), _Bound_indexes());
return this->__call<_Result>(
tuple<_Args...>(std::forward<_Args...>(__args)...),
_Bound_indexes());
}
// Call as const volatile
template<typename... _Args>
result_type
operator()(_Args&... __args) const volatile
operator()(_Args&&... __args) const volatile
{
return this->__call<_Result>(tie(__args...), _Bound_indexes());
return this->__call<_Result>(
tuple<_Args...>(std::forward<_Args...>(__args)...),
_Bound_indexes());
}
};
......@@ -1424,7 +1407,8 @@ namespace std
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...);
return __result_type(__maybe_type::__do_wrap(__f),
std::forward<_ArgTypes>(__args)...);
}
template<typename _Result, typename _Functor, typename... _ArgTypes>
......@@ -1438,7 +1422,8 @@ namespace std
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...);
return __result_type(__maybe_type::__do_wrap(__f),
std::forward<_ArgTypes>(__args)...);
}
/**
......
// <mutex> -*- C++ -*-
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
......@@ -722,12 +722,12 @@ namespace std
call_once(once_flag& __once, _Callable __f, _Args&&... __args)
{
#ifdef _GLIBCXX_HAVE_TLS
auto __bound_functor = std::bind(__f, __args...);
auto __bound_functor = std::bind<void>(__f, __args...);
__once_callable = &__bound_functor;
__once_call = &__once_call_impl<decltype(__bound_functor)>;
#else
unique_lock<mutex> __functor_lock(__get_once_mutex());
__once_functor = std::bind(__f, __args...);
__once_functor = std::bind<void>(__f, __args...);
__set_once_functor_lock_ptr(&__functor_lock);
#endif
......
// Copyright (C) 2010 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.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 20.7.11 Function template bind
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
#include <functional>
using namespace std;
using namespace std::placeholders;
void test01()
{
bind(multiplies<int>(),4,_1)(5);
}
// Copyright (C) 2010 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.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 20.7.11 Function template bind
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
#include <functional>
void goo(int);
void foo() {
std::bind (goo,1)();
std::bind (goo,std::placeholders::_1)(1);
}
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2010 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.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 20.7.11 Function template bind
#include <functional>
void f( int ) {}
void test01()
{
std::function< void( int ) > pf = std::bind( &f, std::placeholders::_1 );
pf(1);
}
// Copyright (C) 2010 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.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 20.7.11 Function template bind
// { dg-options "-std=gnu++0x" }
#include <functional>
#include <testsuite_hooks.h>
using namespace std::placeholders;
int inc(int& i) { return ++i; }
void test01()
{
int counter = 0;
std::bind(&inc, _1)(counter);
VERIFY(counter == 1 );
std::bind(&inc, std::ref(counter))();
VERIFY(counter == 2 );
}
struct Inc
{
int operator()(int& i) const { return ++i; }
void operator()(int&&) const { }
int f(int& i) const { return ++i; }
};
void test02()
{
int counter = 0;
std::bind(Inc(), _1)(counter);
VERIFY(counter == 1 );
std::bind(&Inc::f, Inc(), std::ref(counter))();
VERIFY(counter == 2 );
}
int main()
{
test01();
test02();
}
// Copyright (C) 2010 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.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 20.7.11 Function template bind
// { dg-do compile }
// { dg-options "-std=gnu++0x" }
#include <functional>
using namespace std::placeholders;
int inc(int& i) { return ++i; }
void test01()
{
const int dummy = 0;
std::bind(&inc, _1)(0); // { dg-error ""}
std::bind(&inc, std::ref(dummy))(); // { dg-error ""}
std::bind(&inc, dummy)(); // { dg-error ""}
std::bind(&inc, 0)(); // { dg-error ""}
}
struct Inc
{
int operator()(int& i) const { return ++i; }
void operator()(int&&) const { }
int f(int&& i) const { return ++i; }
};
void test02()
{
const int dummy = 0;
std::bind(Inc(), _1)(dummy); // { dg-error ""}
std::bind(&Inc::f, Inc(), std::ref(dummy))(); // { dg-error ""}
}
int main()
{
test01();
test02();
}
// { dg-excess-errors "" }
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2010 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
......@@ -54,27 +54,19 @@ void test01()
verify_return_type((*pr1)(0), double());
std::reference_wrapper<double (*)(int)>* pr2(0);
verify_return_type((*pr2)(0), double());
std::reference_wrapper<int (test_type::*)()>* pr3(0);
verify_return_type((*pr3)(null_tt), int());
std::reference_wrapper<int (test_type::*)()const>* pr4(0);
verify_return_type((*pr4)(null_ttc), int());
std::reference_wrapper<functor1>* pr5(0);
// libstdc++/24803
// FIXME: verify_return_type((*pr5)(0), double());
verify_return_type((*pr5)(0), double());
verify_return_type((*pr5)(zero), double());
std::reference_wrapper<double (int, char)>* pr1b(0);
verify_return_type((*pr1b)(0,0), double());
std::reference_wrapper<double (*)(int, char)>* pr2b(0);
verify_return_type((*pr2b)(0,0), double());
std::reference_wrapper<int (test_type::*)(char)>* pr3b(0);
verify_return_type((*pr3b)(null_tt,zero), int());
std::reference_wrapper<int (test_type::*)()const>* pr4b(0);
verify_return_type((*pr4b)(null_ttc), int());
std::reference_wrapper<functor2>* pr5b(0);
// libstdc++/24803
// FIXME: verify_return_type((*pr5b)(0,0), double());
verify_return_type((*pr5b)(0,0), double());
verify_return_type((*pr5b)(zero,zero), double());
}
// { dg-options "-std=gnu++0x" }
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2010 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
......@@ -70,11 +70,6 @@ void test01()
::get_seventeen get_sev;
::X x;
::X* xp = &x;
int (::X::* p_foo)(float) = &::X::foo;
int (::X::* p_foo_c)(float) const = &::X::foo_c;
int (::X::* p_foo_v)(float) volatile = &::X::foo_v;
int (::X::* p_foo_cv)(float) const volatile = &::X::foo_cv;
int ::X::* p_bar = &::X::bar;
const float pi = 3.14;
......@@ -86,20 +81,6 @@ void test01()
VERIFY(cref(&truncate_float)(pi) == 3);
VERIFY(cref(&seventeen)() == 17);
// Member function pointers
VERIFY(ref(p_foo)(x, pi) == 3);
VERIFY(ref(p_foo)(xp, pi) == 3);
VERIFY(ref(p_foo_c)(x, pi) == 3);
VERIFY(ref(p_foo_c)(xp, pi) == 3);
VERIFY(ref(p_foo_v)(x, pi) == 3);
VERIFY(ref(p_foo_v)(xp, pi) == 3);
VERIFY(ref(p_foo_cv)(x, pi) == 3);
VERIFY(ref(p_foo_cv)(xp, pi) == 3);
// Member data pointers
VERIFY(ref(p_bar)(x) == 17);
VERIFY(ref(p_bar)(xp) == 17);
// Function objects
VERIFY(ref(get_sev)() == 17);
VERIFY(cref(get_sev)() == 17);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment