]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #include <boost/config.hpp> |
2 | ||
3 | #if defined(BOOST_MSVC) | |
4 | #pragma warning(disable: 4786) // identifier truncated in debug info | |
5 | #pragma warning(disable: 4710) // function not inlined | |
6 | #pragma warning(disable: 4711) // function selected for automatic inline expansion | |
7 | #pragma warning(disable: 4514) // unreferenced inline removed | |
8 | #endif | |
9 | ||
10 | // | |
11 | // bind_as_compose.cpp - function composition using bind.hpp | |
12 | // | |
13 | // Version 1.00.0001 (2001-08-30) | |
14 | // | |
15 | // Copyright (c) 2001 Peter Dimov and Multi Media Ltd. | |
16 | // | |
17 | // Distributed under the Boost Software License, Version 1.0. (See | |
18 | // accompanying file LICENSE_1_0.txt or copy at | |
19 | // http://www.boost.org/LICENSE_1_0.txt) | |
20 | // | |
21 | ||
f67539c2 | 22 | #include <boost/bind/bind.hpp> |
7c673cae FG |
23 | #include <iostream> |
24 | #include <string> | |
25 | ||
f67539c2 TL |
26 | using namespace boost::placeholders; |
27 | ||
7c673cae FG |
28 | std::string f(std::string const & x) |
29 | { | |
30 | return "f(" + x + ")"; | |
31 | } | |
32 | ||
33 | std::string g(std::string const & x) | |
34 | { | |
35 | return "g(" + x + ")"; | |
36 | } | |
37 | ||
38 | std::string h(std::string const & x, std::string const & y) | |
39 | { | |
40 | return "h(" + x + ", " + y + ")"; | |
41 | } | |
42 | ||
43 | std::string k() | |
44 | { | |
45 | return "k()"; | |
46 | } | |
47 | ||
48 | template<class F> void test(F f) | |
49 | { | |
50 | std::cout << f("x", "y") << '\n'; | |
51 | } | |
52 | ||
53 | int main() | |
54 | { | |
55 | using namespace boost; | |
56 | ||
57 | // compose_f_gx | |
58 | ||
59 | test( bind(f, bind(g, _1)) ); | |
60 | ||
61 | // compose_f_hxy | |
62 | ||
63 | test( bind(f, bind(h, _1, _2)) ); | |
64 | ||
65 | // compose_h_fx_gx | |
66 | ||
67 | test( bind(h, bind(f, _1), bind(g, _1)) ); | |
68 | ||
69 | // compose_h_fx_gy | |
70 | ||
71 | test( bind(h, bind(f, _1), bind(g, _2)) ); | |
72 | ||
73 | // compose_f_k | |
74 | ||
75 | test( bind(f, bind(k)) ); | |
76 | ||
77 | return 0; | |
78 | } |