blob: 7195d18c5d797b7659493e5c0abf32b0175106ae (
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
|
// file : tests/cxx/hybrid/iterator/driver.cxx
// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
// Test conformance to STL iterator requirements.
//
#include <cassert>
#include <iostream>
#include <algorithm>
#include "test.hxx"
using namespace std;
using namespace test;
struct fix_pred
{
fix_pred (int v): v_ (v) {}
bool operator() (const fix& x) const {return x.a () == v_;}
int v_;
};
struct var_pred
{
var_pred (const char* v): v_ (v) {}
bool operator() (const var& x) const {return x.a () == v_;}
const char* v_;
};
int
main ()
{
type::f_sequence fs;
fix f;
f.a (1);
fs.push_back (f);
f.a (2);
fs.push_back (f);
f.a (3);
fs.push_back (f);
assert (find_if (fs.begin (), fs.end (), fix_pred (2))->a () == 2);
type::v_sequence vs;
var* v;
v = new var;
v->a ("a");
vs.push_back (v);
v = new var;
v->a ("b");
vs.push_back (v);
v = new var;
v->a ("c");
vs.push_back (v);
assert (find_if (vs.begin (), vs.end (), var_pred ("b"))->a () == "b");
return 0;
}
|