blob: 3dfb1f02d2a2247729aa3dedd6d70f687134781e [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <functional>
Marshall Clow7d210c72017-04-13 18:25:32 +000011// REQUIRES: c++98 || c++03 || c++11 || c++14
Howard Hinnant3e519522010-05-11 19:42:16 +000012
Howard Hinnant5cf4e1f2010-08-22 00:20:12 +000013// template <class Fn>
14// class binder2nd
Howard Hinnant3e519522010-05-11 19:42:16 +000015// : public unary_function<typename Fn::first_argument_type, typename Fn::result_type>
Howard Hinnant5cf4e1f2010-08-22 00:20:12 +000016// {
17// protected:
18// Fn op;
19// typename Fn::second_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;
Howard Hinnant3e519522010-05-11 19:42:16 +000025// };
26
27#include <functional>
28#include <type_traits>
29#include <cassert>
30
31#include "../test_func.h"
32
33class test
34 : public std::binder2nd<test_func>
35{
36 typedef std::binder2nd<test_func> base;
37public:
38 test() : std::binder2nd<test_func>(test_func(3), 4.5) {}
39
40 void do_test()
41 {
42 static_assert((std::is_base_of<
43 std::unary_function<test_func::first_argument_type,
44 test_func::result_type>,
45 test>::value), "");
46 assert(op.id() == 3);
47 assert(value == 4.5);
48
49 int i = 5;
50 assert((*this)(i) == 22.5);
51 assert((*this)(5) == 0.5);
52 }
53};
54
55int main()
56{
57 test t;
58 t.do_test();
59}