Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 12
    You can also use type static constexpr int instead of your enum. So the Factorial<0> template would have static constexpr int value = 1, and template <int N> struct Factorial can have static constexpr int value = N * Factorial<N - 1>::value; Commented Aug 7, 2017 at 22:08
  • 3
    @bobobobo this was answered before C++11 and constexpr. Commented Nov 16, 2018 at 22:25
  • I got error when using enum as parameter. <Non-type template argument is not a constant expression>. The possible value of enum is finite, is there any way to make it work. Commented Sep 6, 2020 at 15:36
  • @JustinMeiners same reasoning doesn't get applied if you post a "duplicate question" expecting to get an answer not from 30 years ago... And that comment is useful to me. Commented Sep 19, 2021 at 15:16