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 12 // template <class Fn> 13 // class binder1st 14 // : public unary_function<typename Fn::second_argument_type, typename Fn::result_type> 15 // { 16 // protected: 17 // Fn op; 18 // typename Fn::first_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 #include <functional> 27 #include <type_traits> 28 #include <cassert> 29 30 #include "../test_func.h" 31 32 class test 33 : public std::binder1st<test_func> 34 { 35 typedef std::binder1st<test_func> base; 36 public: test()37 test() : std::binder1st<test_func>(test_func(2), 30) {} 38 do_test()39 void do_test() 40 { 41 static_assert((std::is_base_of< 42 std::unary_function<test_func::second_argument_type, 43 test_func::result_type>, 44 test>::value), ""); 45 assert(op.id() == 2); 46 assert(value == 30); 47 48 double d = 5; 49 assert((*this)(d) == 35); 50 assert((*this)(5) == 25); 51 } 52 }; 53 main()54int main() 55 { 56 test t; 57 t.do_test(); 58 } 59