
#include <iostream>
#include <algorithm>
#include <list>

using namespace std;

// Item
class MyA { };
class MyB { };

template <class T>
class MyItem
{
public:
	void Print();
};

template <>
void MyItem<MyA>::Print()
{
	cout << "MyItem - MyA" << endl;
}

template <>
void MyItem<MyB>::Print()
{
	cout << "MyItem - MyB" << endl;
}

// ItemList
class MyItemList
{
public:
	template <typename T>
	void AddItem(MyItem<T> theItem);

	void PrintItems();

private:
	template <typename T>
	list<MyItem<T>> & GetTypedList();

	list<MyItem<MyA>> myAList;
	list<MyItem<MyB>> myBList;
};

template <typename T>
void MyItemList::AddItem(MyItem<T> theItem)
{
	GetTypedList<T>().push_back(theItem);
}

template <>
list<MyItem<MyA>> & MyItemList::GetTypedList()
{
	return myAList;
}

template <>
list<MyItem<MyB>> & MyItemList::GetTypedList()
{
	return myBList;
}

void MyItemList::PrintItems()
{
	// Reihenfolge ist uns mal egal
	for_each(myAList.cbegin(), myAList.cend(), [](MyItem<MyA> i)
	{
		i.Print();
	});

	for_each(myBList.cbegin(), myBList.cend(), [](MyItem<MyB> i)
	{
		i.Print();
	});
}

// main
int main(int argc, char * argv[])
{
	MyItemList itemList;

	// itemList soll die Elemente tatsächlich besitzen
	{
		itemList.AddItem(MyItem<MyA>());
		itemList.AddItem(MyItem<MyB>());
	}

	itemList.PrintItems();

	return 0;
}
