2

I have the following aliased template:

#include <vector>

template <typename T>
using MyVector = std::vector <T>;

How can i forward declare MyVector?

template <typename T>
class MyVector;

does not work for me.

Daniel Heilper
  • 1,182
  • 2
  • 17
  • 34
Jonathan
  • 31
  • 6

2 Answers2

2

You might be able to get away with making it a type, which you will be able to forward-declare:

template <typename T>
struct MyVector: std::vector<T> {};
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68
1

You cannot forward declare an using declaration.
Anyway, you can declare forward a sort of traits as it follows:

#include <type_traits>
#include <vector>

template<typename>
struct MyStuff;

template<typename T>
auto f() { return typename MyStuff<T>::MyVector{}; }

template<typename T>
struct MyStuff {
    using MyVector = std::vector<T>;
};

int main() {
    static_assert(std::is_same<decltype(f<int>()), std::vector<int>>::value, "!");
}
skypjack
  • 49,335
  • 19
  • 95
  • 187