summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/phoenix/test/operator/member.cpp
blob: 1abd22d3a80398ff2e262ef532de97b073a411ad (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
/*=============================================================================
    Copyright (c) 2005-2007 Dan Marsden
    Copyright (c) 2005-2007 Joel de Guzman
    Copyright (c) 2014      John Fletcher

    Distributed under 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/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/detail/lightweight_test.hpp>
//#include <boost/move/unique_ptr.hpp>

#include <memory>

#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>

namespace
{
    struct Test
    {
        int value;

        int func(int n) const { return n; }
        int dunc() { return 10; }
        int kunc() const { return 555; }
    };
}

namespace phoenix = boost::phoenix;

int main()
{
    using boost::scoped_ptr;
    using boost::shared_ptr;
    using phoenix::val;
    using phoenix::ref;
    using phoenix::arg_names::arg1;
    using phoenix::arg_names::arg2;

    Test test = {1};
    const Test* cptr = &test;
    Test* ptr = &test;

    BOOST_TEST((val(ptr)->*&Test::value)() == 1);
    BOOST_TEST((val(cptr)->*&Test::value)() == 1);
    BOOST_TEST((arg1->*&Test::value)(cptr) == 1);

    ((val(ptr)->*&Test::value) = 2)();
    BOOST_TEST(test.value == 2);


    BOOST_TEST((val(ptr)->*&Test::func)(val(3))() == 3);
    int i = 33;
    BOOST_TEST((arg1->*&Test::func)(arg2)(cptr, i) == i);
    //BOOST_TEST((val(cptr)->*&Test::func)(4)() == 4);
    BOOST_TEST((val(ptr)->*&Test::dunc)()() == 10);

    BOOST_TEST((arg1->*&Test::func)(5)(ptr) == 5);
    BOOST_TEST((arg1->*&Test::kunc)()(ptr));

    shared_ptr<Test> sptr(new Test(test));

    BOOST_TEST((arg1->*&Test::value)(sptr) == 2);
    BOOST_TEST((arg1->*&Test::func)(6)(sptr) == 6);

    scoped_ptr<Test> scptr(new Test(test));

    BOOST_TEST((arg1->*&Test::value)(scptr) == 2);
    BOOST_TEST((arg1->*&Test::func)(7)(scptr) == 7);

    shared_ptr<const Test> csptr(new Test(test));

    BOOST_TEST((arg1->*&Test::value)(csptr) == 2);
    BOOST_TEST((arg1->*&Test::func)(8)(csptr) == 8);

    scoped_ptr<const Test> cscptr(new Test(test));

    BOOST_TEST((arg1->*&Test::value)(cscptr) == 2);
    BOOST_TEST((arg1->*&Test::func)(9)(cscptr) == 9);

#ifdef BOOST_NO_CXX11_SMART_PTR
    std::auto_ptr<Test> aptr(new Test(test));
#else
    std::unique_ptr<Test> aptr(new Test(test));
#endif

    BOOST_TEST((arg1->*&Test::value)(aptr) == 2);
    BOOST_TEST((arg1->*&Test::func)(10)(aptr) == 10);

#ifdef BOOST_NO_CXX11_SMART_PTR
    std::auto_ptr<const Test> captr(new Test(test));
#else
    std::unique_ptr<const Test> captr(new Test(test));
#endif

    BOOST_TEST((arg1->*&Test::value)(captr) == 2);
    BOOST_TEST((arg1->*&Test::func)(11)(captr) == 11);

    //boost::movelib::unique_ptr<Test> buptr(new Test(test));
    //BOOST_TEST((arg1->*&Test::value)(buptr) == 2);
    //BOOST_TEST((arg1->*&Test::func)(12)(buptr) == 12);


    return boost::report_errors();
}