0

I would like to ask if it is possible to insert static assert into template parameters.

Let´s say I want to create class StaticArray<T,N> and I want to make it impossible for users to instantiate this class with size equal to 0. Is there any way to insert something like static_assert(N != 0, "error message") into my class?

Alexander Bily
  • 925
  • 5
  • 18

1 Answers1

6
template <typename T, std::size_t N>
class StaticArray
{
    static_assert(N != 0, "error message");
};

LIVE DEMO

Piotr Skotnicki
  • 46,953
  • 7
  • 118
  • 160