1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <functional> 11 // REQUIRES: c++98 || c++03 || c++11 || c++14 12 13 // template <class Fn> 14 // class binder1st 15 // : public unary_function<typename Fn::second_argument_type, typename Fn::result_type> 16 // { 17 // protected: 18 // Fn op; 19 // typename Fn::first_argument_type value; 20 // public: 21 // binder2nd(const Fn& x, const typename Fn::second_argument_type& y); 22 // 23 // typename Fn::result_type operator()(const typename Fn::first_argument_type& x) const; 24 // typename Fn::result_type operator()(typename Fn::first_argument_type& x) const; 25 // }; 26 27 #include <functional> 28 #include <type_traits> 29 #include <cassert> 30 31 #include "../test_func.h" 32 33 class test 34 : public std::binder1st<test_func> 35 { 36 typedef std::binder1st<test_func> base; 37 public: test()38 test() : std::binder1st<test_func>(test_func(2), 30) {} 39 do_test()40 void do_test() 41 { 42 static_assert((std::is_base_of< 43 std::unary_function<test_func::second_argument_type, 44 test_func::result_type>, 45 test>::value), ""); 46 assert(op.id() == 2); 47 assert(value == 30); 48 49 double d = 5; 50 assert((*this)(d) == 35); 51 assert((*this)(5) == 25); 52 } 53 }; 54 main()55int main() 56 { 57 test t; 58 t.do_test(); 59 } 60