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 // REQUIRES: c++03 || c++11 || c++14 11 12 // template <class Fn> 13 // class binder2nd 14 // : public unary_function<typename Fn::first_argument_type, typename Fn::result_type> 15 // { 16 // protected: 17 // Fn op; 18 // typename Fn::second_argument_type value; 19 // public: 20 // binder2nd(const Fn& x, const typename Fn::second_argument_type& y); 21 // 22 // typename Fn::result_type operator()(const typename Fn::first_argument_type& x) const; 23 // typename Fn::result_type operator()(typename Fn::first_argument_type& x) const; 24 // }; 25 26 #define _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: test()40 test() : std::binder2nd<test_func>(test_func(3), 4.5) {} 41 do_test()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 main(int,char **)57int main(int, char**) 58 { 59 test t; 60 t.do_test(); 61 62 return 0; 63 } 64