2025-01-02 11:59:57 +01:00
|
|
|
// Copyright (C) 2010-2025 Free Software Foundation, Inc.
|
2010-01-17 13:29:41 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2022-09-28 12:39:41 +01:00
|
|
|
// { dg-options "-Wdeprecated-declarations" }
|
2016-08-26 12:41:37 +01:00
|
|
|
// { dg-do run { target c++11 } }
|
2010-01-17 13:29:41 +00:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <testsuite_hooks.h>
|
|
|
|
|
2010-10-08 00:44:12 +00:00
|
|
|
// target must be invoked with cv-quals of call wrapper
|
|
|
|
|
2010-01-17 13:29:41 +00:00
|
|
|
struct X
|
|
|
|
{
|
|
|
|
int operator()() { return 0; }
|
|
|
|
int operator()() const { return 1; }
|
2010-10-08 00:44:12 +00:00
|
|
|
int operator()() volatile { return 2; }
|
|
|
|
int operator()() const volatile { return 3; }
|
|
|
|
|
|
|
|
int operator()(int, int, int) { return 0; }
|
|
|
|
int operator()(int, int, int) const { return 1; }
|
|
|
|
int operator()(int, int, int) volatile { return 2; }
|
|
|
|
int operator()(int, int, int) const volatile { return 3; }
|
2010-01-17 13:29:41 +00:00
|
|
|
};
|
|
|
|
|
2010-10-08 00:44:12 +00:00
|
|
|
using std::placeholders::_1;
|
|
|
|
using std::placeholders::_2;
|
|
|
|
|
2010-01-17 13:29:41 +00:00
|
|
|
void test01()
|
|
|
|
{
|
|
|
|
auto b0 = std::bind(X());
|
|
|
|
VERIFY( b0() == 0 );
|
|
|
|
|
|
|
|
const auto b1 = std::bind(X());
|
|
|
|
VERIFY( b1() == 1 );
|
|
|
|
|
2022-09-28 12:39:41 +01:00
|
|
|
#if __cplusplus <= 201703L
|
2010-10-08 00:44:12 +00:00
|
|
|
volatile auto b2 = std::bind(X());
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
2010-10-08 00:44:12 +00:00
|
|
|
|
|
|
|
const volatile auto b3 = std::bind(X());
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
Make std::bind use std::invoke
* include/std/functional (_Mu<A, false, true>, _Mu<A, true, false>):
Simplify forwarding from tuple of references.
(_Maybe_wrap_member_pointer): Remove.
(_Bind::__call, _Bind::__call_c, _Bind::__call_v, _Bind::__call_c_v):
Use std::__invoke.
(_Bind::_Mu_type, _Bind::_Res_type_impl, _Bind::_Res_type)
(_Bind::__dependent, _Bind::_Res_type_cv): New helpers to simplify
return type deduction.
(_Bind::operator(), _Bind::operator() const): Use new helpers.
(_Bind::operator() volatile, _Bind::operator() const volatile):
Likewise. Add deprecated attribute for C++17 mode.
(_Bind_result::__call): Use std::__invoke.
(_Bind_result::operator() volatile)
(_Bind_result::operator() const volatile): Add deprecated attribute.
(_Bind_helper::__maybe_type, _Bindres_helper::__maybe_type): Remove.
(_Bind_helper, _Bindres_helper): Don't use _Maybe_wrap_member_pointer.
(bind, bind<R>): Don't use __maybe_type.
* src/c++11/compatibility-thread-c++0x.cc
(_Maybe_wrap_member_pointer): Define here for compatibility symbols.
* testsuite/20_util/bind/68912.cc: Don't test volatile-qualification
in C++17 mode.
* testsuite/20_util/bind/cv_quals.cc: Likewise.
* testsuite/20_util/bind/cv_quals_2.cc: Likewise.
From-SVN: r241178
2016-10-14 20:04:56 +01:00
|
|
|
#endif
|
2010-10-08 00:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void test02()
|
|
|
|
{
|
|
|
|
auto b0 = std::bind<int>(X());
|
|
|
|
VERIFY( b0() == 0 );
|
|
|
|
|
|
|
|
const auto b1 = std::bind<int>(X());
|
|
|
|
VERIFY( b1() == 1 );
|
|
|
|
|
2022-09-28 12:39:41 +01:00
|
|
|
#if __cplusplus <= 201703L
|
2010-10-08 00:44:12 +00:00
|
|
|
volatile auto b2 = std::bind<int>(X());
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
2010-10-08 00:44:12 +00:00
|
|
|
|
|
|
|
const volatile auto b3 = std::bind<int>(X());
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
Make std::bind use std::invoke
* include/std/functional (_Mu<A, false, true>, _Mu<A, true, false>):
Simplify forwarding from tuple of references.
(_Maybe_wrap_member_pointer): Remove.
(_Bind::__call, _Bind::__call_c, _Bind::__call_v, _Bind::__call_c_v):
Use std::__invoke.
(_Bind::_Mu_type, _Bind::_Res_type_impl, _Bind::_Res_type)
(_Bind::__dependent, _Bind::_Res_type_cv): New helpers to simplify
return type deduction.
(_Bind::operator(), _Bind::operator() const): Use new helpers.
(_Bind::operator() volatile, _Bind::operator() const volatile):
Likewise. Add deprecated attribute for C++17 mode.
(_Bind_result::__call): Use std::__invoke.
(_Bind_result::operator() volatile)
(_Bind_result::operator() const volatile): Add deprecated attribute.
(_Bind_helper::__maybe_type, _Bindres_helper::__maybe_type): Remove.
(_Bind_helper, _Bindres_helper): Don't use _Maybe_wrap_member_pointer.
(bind, bind<R>): Don't use __maybe_type.
* src/c++11/compatibility-thread-c++0x.cc
(_Maybe_wrap_member_pointer): Define here for compatibility symbols.
* testsuite/20_util/bind/68912.cc: Don't test volatile-qualification
in C++17 mode.
* testsuite/20_util/bind/cv_quals.cc: Likewise.
* testsuite/20_util/bind/cv_quals_2.cc: Likewise.
From-SVN: r241178
2016-10-14 20:04:56 +01:00
|
|
|
#endif
|
2010-10-08 00:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void test03()
|
|
|
|
{
|
|
|
|
auto b0 = std::bind(X(), 0, _1, _2);
|
|
|
|
VERIFY( b0(0, 0) == 0 );
|
2010-01-17 13:29:41 +00:00
|
|
|
|
2010-10-08 00:44:12 +00:00
|
|
|
const auto b1 = std::bind(X(), _1, 0, _2);
|
|
|
|
VERIFY( b1(0, 0) == 1 );
|
|
|
|
|
2022-09-28 12:39:41 +01:00
|
|
|
#if __cplusplus <= 201703L
|
2010-10-08 00:44:12 +00:00
|
|
|
volatile auto b2 = std::bind(X(), _1, _2, 0);
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
2010-10-08 00:44:12 +00:00
|
|
|
|
|
|
|
const volatile auto b3 = std::bind(X(), _1, 0, _2);
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
Make std::bind use std::invoke
* include/std/functional (_Mu<A, false, true>, _Mu<A, true, false>):
Simplify forwarding from tuple of references.
(_Maybe_wrap_member_pointer): Remove.
(_Bind::__call, _Bind::__call_c, _Bind::__call_v, _Bind::__call_c_v):
Use std::__invoke.
(_Bind::_Mu_type, _Bind::_Res_type_impl, _Bind::_Res_type)
(_Bind::__dependent, _Bind::_Res_type_cv): New helpers to simplify
return type deduction.
(_Bind::operator(), _Bind::operator() const): Use new helpers.
(_Bind::operator() volatile, _Bind::operator() const volatile):
Likewise. Add deprecated attribute for C++17 mode.
(_Bind_result::__call): Use std::__invoke.
(_Bind_result::operator() volatile)
(_Bind_result::operator() const volatile): Add deprecated attribute.
(_Bind_helper::__maybe_type, _Bindres_helper::__maybe_type): Remove.
(_Bind_helper, _Bindres_helper): Don't use _Maybe_wrap_member_pointer.
(bind, bind<R>): Don't use __maybe_type.
* src/c++11/compatibility-thread-c++0x.cc
(_Maybe_wrap_member_pointer): Define here for compatibility symbols.
* testsuite/20_util/bind/68912.cc: Don't test volatile-qualification
in C++17 mode.
* testsuite/20_util/bind/cv_quals.cc: Likewise.
* testsuite/20_util/bind/cv_quals_2.cc: Likewise.
From-SVN: r241178
2016-10-14 20:04:56 +01:00
|
|
|
#endif
|
2010-01-17 13:29:41 +00:00
|
|
|
}
|
|
|
|
|
2010-10-08 00:44:12 +00:00
|
|
|
void test04()
|
|
|
|
{
|
|
|
|
auto b0 = std::bind<int>(X(), 0, _1, _2);
|
|
|
|
VERIFY( b0(0, 0) == 0 );
|
|
|
|
|
|
|
|
const auto b1 = std::bind<int>(X(), _1, 0, _2);
|
|
|
|
VERIFY( b1(0, 0) == 1 );
|
|
|
|
|
2022-09-28 12:39:41 +01:00
|
|
|
#if __cplusplus <= 201703L
|
2010-10-08 00:44:12 +00:00
|
|
|
volatile auto b2 = std::bind<int>(X(), _1, _2, 0);
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
2010-10-08 00:44:12 +00:00
|
|
|
|
|
|
|
const volatile auto b3 = std::bind<int>(X(), _1, 0, _2);
|
2022-09-28 12:39:41 +01:00
|
|
|
VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
|
Make std::bind use std::invoke
* include/std/functional (_Mu<A, false, true>, _Mu<A, true, false>):
Simplify forwarding from tuple of references.
(_Maybe_wrap_member_pointer): Remove.
(_Bind::__call, _Bind::__call_c, _Bind::__call_v, _Bind::__call_c_v):
Use std::__invoke.
(_Bind::_Mu_type, _Bind::_Res_type_impl, _Bind::_Res_type)
(_Bind::__dependent, _Bind::_Res_type_cv): New helpers to simplify
return type deduction.
(_Bind::operator(), _Bind::operator() const): Use new helpers.
(_Bind::operator() volatile, _Bind::operator() const volatile):
Likewise. Add deprecated attribute for C++17 mode.
(_Bind_result::__call): Use std::__invoke.
(_Bind_result::operator() volatile)
(_Bind_result::operator() const volatile): Add deprecated attribute.
(_Bind_helper::__maybe_type, _Bindres_helper::__maybe_type): Remove.
(_Bind_helper, _Bindres_helper): Don't use _Maybe_wrap_member_pointer.
(bind, bind<R>): Don't use __maybe_type.
* src/c++11/compatibility-thread-c++0x.cc
(_Maybe_wrap_member_pointer): Define here for compatibility symbols.
* testsuite/20_util/bind/68912.cc: Don't test volatile-qualification
in C++17 mode.
* testsuite/20_util/bind/cv_quals.cc: Likewise.
* testsuite/20_util/bind/cv_quals_2.cc: Likewise.
From-SVN: r241178
2016-10-14 20:04:56 +01:00
|
|
|
#endif
|
2010-10-08 00:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-17 13:29:41 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
test01();
|
2010-10-08 00:44:12 +00:00
|
|
|
test02();
|
|
|
|
test03();
|
|
|
|
test04();
|
2010-01-17 13:29:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|