public
Last active

Demonstration of Boost.Range to join multiple containers into a single sequence

  • Download Gist
boost-join-example.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <vector>
#include <deque>
#include <string>
#include <iostream>
#include <boost/range/join.hpp>
 
int main() {
// Iterated-over containers can be different types, as long as the
// value types are the same (string, in this case).
std::vector<std::string> vec1 = { "one", "two", "three" };
std::deque<std::string> deq2 = { "four", "five", "six" };
std::vector<std::string> vec3 = { "seven", "eight", "nine" };
 
auto range1_2 = boost::join(vec1, deq2);
auto range12_3 = boost::join(range1_2, vec3);
 
for (auto it = boost::begin(range12_3); it != boost::end(range12_3); ++it)
std::cout << *it << ' ';
// output: one two three four five six seven eight nine
 
std::cout << std::endl;
 
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.