Skip to content

Instantly share code, notes, and snippets.

@rkennedy
Created January 27, 2012 02:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkennedy/1686647 to your computer and use it in GitHub Desktop.
Save rkennedy/1686647 to your computer and use it in GitHub Desktop.
Demonstration of Boost.Range to join multiple containers into a single sequence
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment