PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/libs/phoenix/test/operator/member.cpp

http://hadesmem.googlecode.com/
C++ | 97 lines | 50 code | 26 blank | 21 comment | 12 complexity | 89fc009ad49dc781856155388d407794 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2005-2007 Dan Marsden
 3    Copyright (c) 2005-2007 Joel de Guzman
 4
 5    Distributed under the Boost Software License, Version 1.0. (See accompanying 
 6    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 7==============================================================================*/
 8
 9#include <boost/phoenix/core.hpp>
10#include <boost/phoenix/operator.hpp>
11#include <boost/detail/lightweight_test.hpp>
12
13#include <memory>
14
15#include <boost/shared_ptr.hpp>
16#include <boost/scoped_ptr.hpp>
17
18namespace
19{
20    struct Test
21    {
22        int value;
23
24        int func(int n) const { return n; }
25        int dunc() { return 10; }
26        int kunc() const { return 555; }
27    };
28}
29
30namespace phoenix = boost::phoenix;
31
32int main()
33{
34    using boost::scoped_ptr;
35    using boost::shared_ptr;
36    using phoenix::val;
37    using phoenix::ref;
38    using phoenix::arg_names::arg1;
39    using phoenix::arg_names::arg2;
40
41    Test test = {1};
42    const Test* cptr = &test;
43    Test* ptr = &test;
44
45    BOOST_TEST((val(ptr)->*&Test::value)() == 1);
46    /*
47    BOOST_TEST((val(cptr)->*&Test::value)() == 1);
48    BOOST_TEST((arg1->*&Test::value)(cptr) == 1);
49    */
50
51    /*
52    ((val(ptr)->*&Test::value) = 2)();
53    BOOST_TEST(test.value == 2);
54    */
55
56
57    BOOST_TEST((val(ptr)->*&Test::func)(3)() == 3);
58    int i = 33;
59    BOOST_TEST((arg1->*&Test::func)(arg2)(cptr, i) == i);
60    BOOST_TEST((val(cptr)->*&Test::func)(4)() == 4);
61    BOOST_TEST((val(ptr)->*&Test::dunc)()() == 10);
62
63    BOOST_TEST((arg1->*&Test::func)(5)(ptr) == 5);
64    BOOST_TEST((arg1->*&Test::kunc)()(ptr));
65
66    shared_ptr<Test> sptr(new Test(test));
67
68    //BOOST_TEST((arg1->*&Test::value)(sptr) == 2);
69    BOOST_TEST((arg1->*&Test::func)(6)(sptr) == 6);
70
71    scoped_ptr<Test> scptr(new Test(test));
72
73    //BOOST_TEST((arg1->*&Test::value)(scptr) == 2);
74    BOOST_TEST((arg1->*&Test::func)(7)(scptr) == 7);
75
76    shared_ptr<const Test> csptr(new Test(test));
77
78    //BOOST_TEST((arg1->*&Test::value)(csptr) == 2);
79    BOOST_TEST((arg1->*&Test::func)(8)(csptr) == 8);
80
81    scoped_ptr<const Test> cscptr(new Test(test));
82
83    //BOOST_TEST((arg1->*&Test::value)(cscptr) == 2);
84    BOOST_TEST((arg1->*&Test::func)(9)(cscptr) == 9);
85
86    std::auto_ptr<Test> aptr(new Test(test));
87
88    //BOOST_TEST((arg1->*&Test::value)(aptr) == 2);
89    BOOST_TEST((arg1->*&Test::func)(10)(aptr) == 10);
90
91    std::auto_ptr<const Test> captr(new Test(test));
92
93    //BOOST_TEST((arg1->*&Test::value)(captr) == 2);
94    BOOST_TEST((arg1->*&Test::func)(11)(captr) == 11);
95
96    return boost::report_errors();
97}