More C++ Idioms/Tag Dispatching

= Tag dispatch =

Intent
Simplify writing multiple SFINAE-constrained overloads.

Motivation
Tag dispatching is a useful complement to. It can also be used in conjunction with trailing return type and, which uses expression SFINAE.

It is most useful when you have multiple overloads for the same function, and they all have conditions for when they can be called. With just, you have to test for not just the overloads condition, but also the negation of all other overloads' conditions, lest you get overload ambiguity. Tag dispatch will help reduce the mess:

Solution
This works because exact match is a better match than a base class, which in turn is a better match than base of base, etc. Tag dispatch can also be used when the tag carries useful information, not just a preference ordering. For example, one can dispatch on  and have different algorithms for  s and  s.

C++20
C++20 added concepts and  statements, which entirely eliminates the need for tag dispatching where the constraints include both   and   or both   and   for some   and   explicitly or in the definitions of concepts. The following code implements  as an example.