I'm coding in C++
What is the shortest function of:
template<T> std::vector<T> make_copy(const deque<T>& d) {
// your code here
}
?
I'm coding in C++
What is the shortest function of:
template<T> std::vector<T> make_copy(const deque<T>& d) {
// your code here
}
?
Can't really compete with UncleBens in terms of program length so instead I'll post the most general solution to the problem:
template<class Src>
struct CopyMaker {
Src const & src;
CopyMaker(Src const & src) : src(src) {
}
template<class Dest>
operator Dest() const {
return Dest(src.begin(), src.end());
}
};
template<class Src>
CopyMaker<Src> make_copy(Src const & src) {
return CopyMaker<Src>(src);
}
int main()
{
std::vector<int> vec;
std::deque<int> deq = make_copy(vec);
std::list<int> list = make_copy(deq);
std::set<int> set = make_copy(list);
}