blob: 645c1688c18af880c89684b0819162f846bfb9b6 [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>
11
Howard Hinnant5cf4e1f2010-08-22 00:20:12 +000012// template <class Fn>
13// class binder2nd
Howard Hinnant3e519522010-05-11 19:42:16 +000014// : public unary_function<typename Fn::first_argument_type, typename Fn::result_type>
Howard Hinnant5cf4e1f2010-08-22 00:20:12 +000015// {
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;
Howard Hinnant3e519522010-05-11 19:42:16 +000024// };
25
26#include <functional>
27#include <type_traits>
28#include <cassert>
29
30#include "../test_func.h"
31
32class test
33 : public std::binder2nd<test_func>
34{
35 typedef std::binder2nd<test_func> base;
36public:
37 test() : std::binder2nd<test_func>(test_func(3), 4.5) {}
38
39 void do_test()
40 {
41 static_assert((std::is_base_of<
42 std::unary_function<test_func::first_argument_type,
43 test_func::result_type>,
44 test>::value), "");
45 assert(op.id() == 3);
46 assert(value == 4.5);
47
48 int i = 5;
49 assert((*this)(i) == 22.5);
50 assert((*this)(5) == 0.5);
51 }
52};
53
54int main()
55{
56 test t;
57 t.do_test();
58}