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