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
|
// http://ideone.com/OSQ5eF
#include <list>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <iterator>
#include <functional>
template <typename C1, typename C2>
void assign(C1& target, const C2& source)
{
using std::begin; using std::end;
target.assign(begin(source), end(source));
}
template <typename C>
void print(const C& c)
{
for (auto& e : c)
std::cout << e << '\n';
std::cout << '\n';
}
int main()
{
std::vector<std::string> v;
std::list<const char*> list = { "aaa", "bbb", "ccc" };
std::set<const char*, std::less<std::string>> set = { "one", "two", "three", "four" };
const char* array[] = { "one", "two", "three", "four" };
assign(v, list);
print(v);
assign(v, set);
print(v);
assign(v, array);
print(v);
}
|