rkennedy
1/27/2012 - 2:48 AM

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

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;
}