PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://hadesmem.googlecode.com/
C++ | 60 lines | 42 code | 11 blank | 7 comment | 8 complexity | 5aad65c2a191d1f2d8b6bec9724168a2 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2007 Joel de Guzman
 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 <vector>
 8#include <string>
 9#include <map>
10#include <boost/detail/lightweight_test.hpp>
11#include <boost/phoenix/core.hpp>
12#include <boost/phoenix/operator.hpp>
13
14namespace phoenix = boost::phoenix;
15
16int
17main()
18{
19    using phoenix::ref;
20    using phoenix::arg_names::arg1;
21    using phoenix::arg_names::arg2;
22    using std::map;
23    using std::string;
24    using std::vector;
25    
26    {
27        int x = 123;
28        BOOST_TEST((&arg1)(x) == &x);
29        //BOOST_TEST((*&arg1)(x) == 123);
30
31        int y = 968;
32        (ref(x) = arg1)(y);
33        BOOST_TEST(x == y);
34
35        (arg1 = 456)(x);
36        BOOST_TEST(x == 456);
37        int& r = (arg1 = 456)(x); // must be an lvalue
38        BOOST_TEST(&r == &x);
39
40        int c[] = { 1, 2, 3, 4, 5 };
41        BOOST_TEST((arg1[3])(c) == 4);
42
43        int& r2 = (arg1[3])(c); // must be an lvalue
44        BOOST_TEST(&r2 == &c[3]);
45
46        vector<string> v;
47        v.push_back("a");
48        v.push_back("b");
49        v.push_back("c");
50        v.push_back("d");
51
52        BOOST_TEST((arg1[3])(v) == "d");
53
54        map<string, int> m;
55        (arg1["Kimpo"] = arg2)(m, x);
56        BOOST_TEST(m["Kimpo"] == x);
57    }
58
59    return boost::report_errors();
60}