File: stl_tests.cpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (95 lines) | stat: -rw-r--r-- 2,788 bytes parent folder | download | duplicates (10)
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
/*=============================================================================
    Phoenix V1.2.1
    Copyright (c) 2001-2003 Joel de Guzman

    Use, modification and distribution is 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 <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <boost/detail/lightweight_test.hpp>

#define PHOENIX_LIMIT 15
#include <boost/spirit/include/phoenix1_primitives.hpp>
#include <boost/spirit/include/phoenix1_composite.hpp>
#include <boost/spirit/include/phoenix1_functions.hpp>
#include <boost/spirit/include/phoenix1_operators.hpp>
#include <boost/spirit/include/phoenix1_binders.hpp>
#include <boost/spirit/include/phoenix1_special_ops.hpp>

using namespace phoenix;
using namespace std;

    ///////////////////////////////////////////////////////////////////////////////
    struct print_ { // a typical STL style monomorphic functor

        typedef void result_type;
        void operator()(int n0)         { cout << "got 1 arg " << n0 << " \n"; }
    };

    functor<print_> print = print_();

///////////////////////////////////////////////////////////////////////////////
int
main()
{

///////////////////////////////////////////////////////////////////////////////
//
//  STL algorithms
//
///////////////////////////////////////////////////////////////////////////////
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);

    for_each(v.begin(), v.end(), arg1 *= 2);
    for (int m = 0; m < 5; ++m, (cout << ','))
    {
        cout << v[m];
        BOOST_TEST(v[m] == (m+1)*2);
    }
    cout << endl;

    for_each(v.begin(), v.end(), print(arg1));

    vector<int>::iterator it = find_if(v.begin(), v.end(), arg1 > 5);
    if (it != v.end())
        cout << *it << endl;

///////////////////////////////////////////////////////////////////////////////
//
//  STL iterators and containers
//
///////////////////////////////////////////////////////////////////////////////

    BOOST_TEST((arg1[0])(v) == v[0]);
    BOOST_TEST((arg1[1])(v) == v[1]);

    list<int> l;
    l.push_back(1);
    l.push_back(2);
    l.push_back(3);
    l.push_back(4);
    l.push_back(5);

    list<int>::iterator first = l.begin();
    list<int>::iterator last = l.end();

    BOOST_TEST((*(++arg1))(first) == 2);
    BOOST_TEST((*(----arg1))(last) == 4);

///////////////////////////////////////////////////////////////////////////////
//
//  End asserts
//
///////////////////////////////////////////////////////////////////////////////

    return boost::report_errors();    
}