#include <iostream>
#include <list> #include <vector> template <typename A, typename B> struct Iterator { /* typedef typename std::common_type<typename A::type, typename B::type>::type type; */ typedef typename A::type type; Iterator & operator++() { if (....) { ++ita; } else { ++itb; } } typename type operator*() { if (....) { return *ita; } else { return *itb; } } const A &a; const B &b; /* ??? */ inAStillSomeLeft; /* */ ita; /* */ itb; }; template <typename A, typename B> struct Concat { Concat(const A &a, const B &b) : a(a), b(b) { } Iterator<A,B> begin() const { return Iterator<A,B>(a, b, /* code for begin*/); } Iterator<A,B> end() const { return Iterator<A,B>(a, b, /* code for end */); } const A::const_iterator a; const B::const_iterator b; }; template <typename A, typename B> Concat<A,B> concat(const A &a, const B &b) { return Concat<A,B>(a,b); } int main() { std::vector<int> a = {1, 2, 3}; std::list<int> b = {4, 5, 6}; //char text[6] = "Hello"; // C++11 for (int i : a) { std::cout << i << std::endl; } for (int i : b) { std::cout << i << std::endl; } for (int i : concat(a, b)) { std::cout << i << std::endl; } for (auto it=concat(a,b).begin(); it!=concat(a,b).end(); ++it) { std::cout << *it << std::endl; } } |