Reputation: 153
I want to define a std::vector
with 2 elements as a type, and export it.
Something looking like:
template <class T>
using Vec2 = std::vector<T>(2);
Edit: A lot of interesting responses. Thanks to everyone, I will use a typedef struct because I don't really need to access container's member functions.
Upvotes: 0
Views: 106
Reputation: 122575
No. This is not possible because a std::vector<int>
of size 2
has the same type as a std::vector<int>
of size 42
. Vectors are resizable, thats basically what makes them vectors and distinguishes them from std::array
. For a container of fixed size 2
you can use arrays:
template <class T>
using Vec2 = std::array<T,2>;
Upvotes: 3