Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"indexitor" container now handles skips correctly.

13 views
Skip to first unread message

Mr Flibble

unread,
Feb 20, 2017, 5:18:54 PM2/20/17
to
Hi!

My indexitor container now handles skips correctly:

#include <string>
#include <iostream>
#include <neolib/indexitor.hpp>

int main()
{
neolib::indexitor<std::string, int> idx;
typedef neolib::indexitor<std::string, int>::skip_type skip;

idx.push_back(std::make_pair("xyzzy", 5), skip{ 2, 2 });
idx.push_back(std::make_pair("neo", 5), skip{ 5, 0 });
idx.push_back(std::make_pair("kitteh", 5), skip{ 3, 1 });

for (auto i = idx.begin(); i != idx.end(); ++i)
std::cout << "Foreign index of " << i->first << " is " <<
idx.foreign_index(i) << std::endl;

std::cout << "All foreign indexes:-" << std::endl;
for (int i = 0; i < idx.foreign_index(idx.end()); ++i)
{
auto v = idx.find_by_foreign_index(i);
if (v.first != idx.end())
std::cout << i << ": " << v.first->first << std::endl;
else
std::cout << i << ": <null>" << std::endl;
}

return 0;
}


outputs:

Foreign index of xyzzy is 2
Foreign index of neo is 14
Foreign index of kitteh is 22
All foreign indexes:-
0: <null>
1: <null>
2: xyzzy
3: xyzzy
4: xyzzy
5: xyzzy
6: xyzzy
7: <null>
8: <null>
9: <null>
10: <null>
11: <null>
12: <null>
13: <null>
14: neo
15: neo
16: neo
17: neo
18: neo
19: <null>
20: <null>
21: <null>
22: kitteh
23: kitteh
24: kitteh
25: kitteh
26: kitteh
27: <null>

Get indexitor from: https://github.com/FlibbleMr/neolib

/Flibble
0 new messages