I suppose this is trivial for people who know patterns ...
Suppose we need two different implementations of this template, depending on the value of N:
template <int N> class Foo { ... };
For instance:
template <int N> class Foo { ... // implementation for N <= 10 }; template <int N> class Foo { ... // implementation for N > 10 };
How can we do this in C ++ 11?
Use the optional template parameter with a default value to distinguish between cases:
template <int N, bool b = N <= 10> class Foo; template <int N> class Foo<N, true> { ... // implementation for N <= 10 }; template <int N> class Foo<N, false> { ... // implementation for N > 10 };
Source: https://habr.com/ru/post/971536/More articles:GIT :: Merging 2 branches rewrites content in one branch with another - gitOData query filter for dateTime range - odataHow to install PySide on Travis? - pythonProblem with NAT bypass with video conferencing using webrtc - phpSwift: optional array counter - arraysGrails maven plugin wants Groovy 2.4.2 - javaHow to get check / change history for a specific team project? - c #How to make my version of the debugging app receive product release notifications on iOS? - iosImage loading does not work on server - c #Python attachment in C ++: ImportError: no module named pyfunction - c ++All Articles