PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/phoenix/test/function/adapt_function.cpp

http://hadesmem.googlecode.com/
C++ | 74 lines | 58 code | 10 blank | 6 comment | 4 complexity | e9591efcd41b63331d7ebee1a649cc44 MD5 | raw file
 1/*=============================================================================
 2  Copyright (c) 2011 Thomas Heller
 3
 4  Distributed under the Boost Software License, Version 1.0. (See accompanying 
 5  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 6  ==============================================================================*/
 7#include <iostream>
 8#include <cmath>
 9#include <boost/detail/lightweight_test.hpp>
10#include <boost/phoenix/core.hpp>
11#include <boost/phoenix/function.hpp>
12
13namespace impl
14{
15    void
16    test()
17    {
18        std::cout << "Test adapting functions...\n";
19    }
20
21    int
22    negate(int n)
23    {
24        return -n;
25    }
26
27    int
28    plus(int a, int b)
29    {
30        return a + b;
31    }
32
33    template <typename T>
34    T
35    plus(T a, T b, T c)
36    {
37        return a + b + c;
38    }
39
40    int
41    plus4(int a, int b, int c, int d)
42    {
43        return a + b + c + d;
44    }
45}
46    
47BOOST_PHOENIX_ADAPT_FUNCTION_NULLARY(void, test, impl::test)
48BOOST_PHOENIX_ADAPT_FUNCTION(int, negate, impl::negate, 1)
49BOOST_PHOENIX_ADAPT_FUNCTION(int, plus, impl::plus, 2)
50BOOST_PHOENIX_ADAPT_FUNCTION(
51    typename boost::remove_reference<A0>::type
52  , plus
53  , impl::plus
54  , 3
55)
56BOOST_PHOENIX_ADAPT_FUNCTION(int, plus4, impl::plus4, 4)
57
58int
59main()
60{
61    using boost::phoenix::arg_names::arg1;
62    using boost::phoenix::arg_names::arg2;
63
64    int a = 123;
65    int b = 256;
66
67    test()();
68    BOOST_TEST(::negate(arg1)(a) == -a);
69    BOOST_TEST(::plus(arg1, arg2)(a, b) == a+b);
70    BOOST_TEST(::plus(arg1, arg2, 3)(a, b) == a+b+3);
71    BOOST_TEST(plus4(arg1, arg2, 3, 4)(a, b) == a+b+3+4);
72
73    return boost::report_errors();
74}