I have written a simple C++11 style stateful allocator type. Given
template<typename T> class my_allocator {
// the usual stuff
};
template<typename T> using my_vector = std::vector<T, my_allocator<T>>;
my_vector<int> x;
std::vector<int> y = x; // error
What is the best way to allow conversions from a my_vector
to a std::vector
using the default allocator? GCC 4.7 (recent svn) says
error: conversion from 'my_vector<int> {aka std::vector<int, my_allocator<int>>}' to non-scalar type 'std::vector<int>' requested
Obviously this could be done with, say, a simple conversion function such as
template<typename T> std::vector<T> to_std_vec(const my_vector<T>& v) {
return std::vector<T>(&v[0], &v[v.size()]);
}
but this seems pretty inelegant. Is there a better solution in C++11?
Move semantics are right out in this situation, of course, but I'd like copy construction and assignment to work without extra noise/typing.