Created
January 27, 2012 02:48
-
-
Save rkennedy/1686647 to your computer and use it in GitHub Desktop.
Demonstration of Boost.Range to join multiple containers into a single sequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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