1
Fork 0
turbonss/cxxmph/hollow_iterator_test.cc

46 lines
1.2 KiB
C++
Raw Normal View History

#include <cstdlib>
#include <cstdio>
#include <vector>
2012-04-15 06:03:00 +03:00
#include <iostream>
2012-04-15 06:03:00 +03:00
using std::cerr;
using std::endl;
using std::vector;
2012-04-15 06:03:00 +03:00
#include "hollow_iterator.h"
using cxxmph::hollow_iterator_base;
using cxxmph::make_hollow;
using cxxmph::is_empty;
int main(int argc, char** argv) {
vector<int> v;
vector<bool> p;
for (int i = 0; i < 100; ++i) {
v.push_back(i);
p.push_back(i % 2 == 0);
}
2012-04-15 06:03:00 +03:00
auto begin = make_hollow(&v, &p, v.begin());
auto end = make_hollow(&v, &p, v.end());
for (auto it = begin; it != end; ++it) {
if (((*it) % 2) != 0) exit(-1);
}
2012-04-15 06:03:00 +03:00
const vector<int>* cv(&v);
auto cbegin(make_hollow(cv, &p, cv->begin()));
auto cend(make_hollow(cv, &p, cv->begin()));
for (auto it = cbegin; it != cend; ++it) {
if (((*it) % 2) != 0) exit(-1);
}
vector<int>::iterator vit1 = v.begin();
vector<int>::const_iterator vit2 = v.begin();
if (vit1 != vit2) exit(-1);
2012-04-15 06:03:00 +03:00
auto it1 = make_hollow(&v, &p, vit1);
auto it2 = make_hollow(&v, &p, vit2);
if (it1 != it2) exit(-1);
2012-04-15 06:03:00 +03:00
typedef is_empty<vector<int>> iev;
hollow_iterator_base<vector<int>::iterator, iev> default_constructed;
default_constructed = make_hollow(&v, &p, v.begin());
return 0;
}