0

I am trying to restrict the scope of my non-type template parameter as much as possible, so this is the parent template:

template <typename _Tp, const std::vector<std::size_t> &_dims>
struct __array_traits{};

and I'm trying to create a specialised template with the non-type template parameter set to a default value, possibly an empty const vector:

template<typename _Tp>
struct __array_traits < _Tp, const std::vector<std::size_t> &&std::vector<std::size_t>{} >
{};

Then the VS linting highlighted the latter const saying 'Type name is not allowed.' and the latter __array_traits saying 'The template argument list of the partial specialization includes a nontype argument whose type depends on a template parameter.'

I'm new to C++ and am quite confused to how templates work. Any help would be much appreciated.

  • You would have to declare a vector and then use a reference to it as the template parameter. However this kind of template parameter is very strange. Are you sure this is the parameter you actually want to have? – user253751 Aug 11 '21 at 15:00
  • 1
    `template struct array_traits{};` seems more appropriate. – Jarod42 Aug 11 '21 at 15:00
  • 1
    I think starting class names with underscores is reserved for the implementation. – Ted Lyngmo Aug 11 '21 at 15:03
  • 2
    Yes, symbols beginning with a single underscore character or a double underscore are forbidden: https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier#:~:text=All%20identifiers%20that%20begin%20with,ordinary%20and%20tag%20name%20spaces. – Daniel Dearlove Aug 11 '21 at 15:07
  • If you are new, then use a book or a tutorial and try code as you learn. Only when you have enough understanding, try to make your own code. Your second code fragment is so strange that we cannot even guess what you are trying to do! – Phil1970 Aug 11 '21 at 17:15
  • Thank you very much for all your comments! Yes, Jarod42's parent template is exactly what I'm trying to achieve. I didn't know the three dots notation exist. – vampiresquid Aug 12 '21 at 00:16
  • [parameter pack](https://en.cppreference.com/w/cpp/language/parameter_pack) is available since C++11 – Jarod42 Aug 12 '21 at 09:15

0 Answers0