Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/bind/bind_as_compose.cpp @ 13

Last change on this file since 13 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.4 KB
Line 
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
22#include <boost/bind.hpp>
23#include <iostream>
24#include <string>
25
26std::string f(std::string const & x)
27{
28    return "f(" + x + ")";
29}
30
31std::string g(std::string const & x)
32{
33    return "g(" + x + ")";
34}
35
36std::string h(std::string const & x, std::string const & y)
37{
38    return "h(" + x + ", " + y + ")";
39}
40
41std::string k()
42{
43    return "k()";
44}
45
46template<class F> void test(F f)
47{
48    std::cout << f("x", "y") << '\n';
49}
50
51int main()
52{
53    using namespace boost;
54
55    // compose_f_gx
56
57    test( bind(f, bind(g, _1)) );
58
59    // compose_f_hxy
60
61    test( bind(f, bind(h, _1, _2)) );
62
63    // compose_h_fx_gx
64
65    test( bind(h, bind(f, _1), bind(g, _1)) );
66
67    // compose_h_fx_gy
68
69    test( bind(h, bind(f, _1), bind(g, _2)) );
70
71    // compose_f_k
72
73    test( bind(f, bind(k)) );
74
75    return 0;
76}
Note: See TracBrowser for help on using the repository browser.