I'm having issues when writing template members of a non template class, specfically when deducing template parameters of a template template argument.
The following code, minimal, illustrates my problem. I suspect there are at least two different problems down there.
#include <iostream>
#include <list>
using namespace std;
struct A
{
list<int> l;
template<template<class> class Iterable>
A(Iterable<int>& it);
};
template<template<class> class Iterable>
A::A(Iterable<int>& it) : l(list<int>())
{
for(int i : it)
l.push_back(i);
}
int main()
{
list<int> l = {1, 2, 3, 4};
A a(l);
for(int i : a.l)
cout << i << " ";
cout << endl;
A b = {1, 2, 3, 4};
for(int i : b.l)
cout << i << " ";
cout << endl;
}
Remarks : I really want to provide the definition out of class. I also want the prototype of the constructor of A
to work with lists of ints, vectors of ints, as well as initializer list.
Aucun commentaire:
Enregistrer un commentaire