| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <functional> |
| 10 |
|
| 11 |
// template <class Fn> |
| 12 |
// class binder2nd |
| 13 |
// : public unary_function<typename Fn::first_argument_type, typename Fn::result_type> |
| 14 |
// { |
| 15 |
// protected: |
| 16 |
// Fn op; |
| 17 |
// typename Fn::second_argument_type value; |
| 18 |
// public: |
| 19 |
// binder2nd(const Fn& x, const typename Fn::second_argument_type& y); |
| 20 |
// |
| 21 |
// typename Fn::result_type operator()(const typename Fn::first_argument_type& x) const; |
| 22 |
// typename Fn::result_type operator()(typename Fn::first_argument_type& x) const; |
| 23 |
// }; |
| 24 |
|
| 25 |
// REQUIRES: c++03 || c++11 || c++14 |
| 26 |
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS |
| 27 |
|
| 28 |
#include <functional> |
| 29 |
#include <type_traits> |
| 30 |
#include <cassert> |
| 31 |
|
| 32 |
#include "test_macros.h" |
| 33 |
#include "../test_func.h" |
| 34 |
|
| 35 |
class test |
| 36 |
: public std::binder2nd<test_func> |
| 37 |
{ |
| 38 |
typedef std::binder2nd<test_func> base; |
| 39 |
public: |
| 40 |
test() : std::binder2nd<test_func>(test_func(3), 4.5) {} |
| 41 |
|
| 42 |
void do_test() |
| 43 |
{ |
| 44 |
static_assert((std::is_base_of< |
| 45 |
std::unary_function<test_func::first_argument_type, |
| 46 |
test_func::result_type>, |
| 47 |
test>::value), ""); |
| 48 |
assert(op.id() == 3); |
| 49 |
assert(value == 4.5); |
| 50 |
|
| 51 |
int i = 5; |
| 52 |
assert((*this)(i) == 22.5); |
| 53 |
assert((*this)(5) == 0.5); |
| 54 |
} |
| 55 |
}; |
| 56 |
|
| 57 |
int main(int, char**) |
| 58 |
{ |
| 59 |
test t; |
| 60 |
t.do_test(); |
| 61 |
|
| 62 |
return 0; |
| 63 |
} |