File: make_fused_function_object.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (95 lines) | stat: -rw-r--r-- 2,673 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*=============================================================================
    Copyright (c) 2006-2007 Tobias Schwinger
  
    Use modification and distribution are subject to the Boost Software 
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt).
==============================================================================*/

#include <boost/fusion/functional/generation/make_fused_function_object.hpp>
#include <boost/detail/lightweight_test.hpp>

#include <boost/core/noncopyable.hpp>
#include <boost/mpl/empty_base.hpp>

#include <boost/fusion/container/generation/make_vector.hpp>
#include <boost/fusion/container/vector.hpp>

namespace fusion = boost::fusion;
using boost::noncopyable;
using boost::cref;
using boost::ref;

template <class Base = boost::mpl::empty_base>
struct test_func
    : Base
{
    template<typename T>
    struct result
    {
    };


    template<class Self, typename T0, typename T1>
    struct result< Self(T0, T1) >
    {
        typedef int type;
    };

    template <typename T0, typename T1>
    int operator()(T0 const & x, T1 const & y) const
    {
        return 1+x-y;
    }

    template <typename T0, typename T1>
    int operator()(T0 const & x, T1 const & y) 
    {
        return 2+x-y;
    }

    template <typename T0, typename T1>
    int operator()(T0 & x, T1 & y) const
    {
        return 3+x-y;
    }

    template <typename T0, typename T1>
    int operator()(T0 & x, T1 & y) 
    {
        return 4+x-y;
    }
};

template <typename T>
inline T const & const_(T const & t)
{
    return t;
}

int main()
{
    fusion::vector<int,char> lv_vec(1,'\004');
    test_func<> f;
    test_func<noncopyable> f_nc;
 
    boost::fusion::result_of::make_fused_function_object< test_func<> >::type fused_func
        = fusion::make_fused_function_object(f);

    BOOST_TEST(fused_func(lv_vec) == 1);
    BOOST_TEST(const_(fused_func)(lv_vec) == 0);
    BOOST_TEST(fusion::make_fused_function_object(const_(f))(lv_vec) == 1);
    BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(lv_vec) == 1);
    BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(lv_vec) == 0);

    BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1);
    BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0);
    BOOST_TEST(fusion::make_fused_function_object(const_(f))(fusion::make_vector(2,'\003')) == 1);
    BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(fusion::make_vector(2,'\003')) == 1);
    BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(fusion::make_vector(2,'\003')) == 0);

    return boost::report_errors();
}