#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;


class A {
	    int val; 
    public:
        A(int x=0) : val(x){}
        A& operator= ( const A &rhs ) { return *this; }
        void show() { cout<<val<<" ";}
        int get() const { return val; }
};
class B: public A {
    public:
        B(int x=0) : A(x) {}
        B( const B& rhs) : A(static_cast<A>(rhs)) {}
        B(const A& rhs) : A(rhs) {}  // <================= WITHOUT THIS CTOR, IT FAILS TO COMPILE 
        B& operator= ( const A &rhs ) { return *this; }
};

int main() {
    A a;
    B b;
    std::list < A > aa{ A(1), A(2), A(3)};
    std::list < B > bb;
    a = b; // works
    b = a; // works
    //std::copy(aa.begin(), aa.end(), bb.begin());  // ouch: to avoid
    //for (auto &x : bb) x.show();  // ouch !! only copies on existing elements 
    std::copy(aa.begin(), aa.end(), back_inserter<list<B>>(bb)); 
    for (auto &x : bb) x.show(); cout<<endl; 
    bb.assign(aa.begin(), aa.end());
    for (auto &x : bb) x.show(); cout<<endl; 
    std::copy(bb.begin(), bb.end(), back_inserter<list<A>>(aa)); 
    std::copy(bb.begin(), bb.end(), aa.begin()); 
   
    std::list <int> xx; 
    std::transform (aa.begin(), aa.end(), std::back_inserter<list<int>>(xx), [](const A&a){return a.get();});     
    std::copy(xx.begin(), xx.end(), std::ostream_iterator<int>(cout,";")); cout<<endl; 
	return 0;
}