将 std::vector<const Type*> 转换为 const std::vector<T, A> &Vec
Convert std::vector<const Type*> to const std::vector<T, A> &Vec
我继承了一些代码,我认为应该是一个简单的更新。
我有以下函数template<typename T>
class ArrayRef {
public:
typedef const T *iterator;
typedef const T *const_iterator;
private:
/// The start of the array, in an external buffer.
const T *Data;
public:
/// Construct an ArrayRef from a std::vector.
template<typename A>
ArrayRef(const std::vector<T, A> &Vec)
: Data(Vec.empty() ? (T*)0 : &Vec[0]), Length(Vec.size()) {}
};
我需要传递一个向量,定义如下,给那个函数
std::vector<const myType*> myVector(4);
最简单的方法是什么?
传递vector:
ArrayRef<const myType*> myArrayRef(myVector);
这对你不起作用有什么原因吗?