1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
#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 = {123};
    std::list<int>   b = {456};

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