Enable a partial specialization only if a boolean condition is true.
You might also want to take a look at when_valid
, which provides similar functionality but enables a specialziation only when some expression is well-formed.
when
is used to control the priority of partial specializations in a finer grained manner than what can be achieved with the usual typename Enable = void
and std::enable_if
pattern. For example, a partially specialized tag-dispatched method will have a higher priority than an equivalent specialization that uses when
. For more details, see the tutorial section on tag-dispatching.