SCC
SCC

Reputation: 720

Convert std::vector<const Type*> to const std::vector<T, A> &Vec

I have inherited some code and am stuck on what I thought should be a simple update.

I have the following function

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()) {}
};

And I need to pass a vector, defined with following, to that function.

std::vector<const myType*> myVector(4);

What is the simplest way to do this?

Upvotes: 0

Views: 451

Answers (1)

Kyle Lutz
Kyle Lutz

Reputation: 8036

Just pass your vector:

ArrayRef<const myType*> myArrayRef(myVector);

Is there some reason this doesn't work for you?

Upvotes: 1

Related Questions