Tag dispatching is basically the name given to the method used to find the right overloaded function. Thus, technically it is only overload only.
To add it from the Boost site:
Sending tags is a way of using function overloads to send based on type properties, and is often used hand in hand with feature classes.
You can see that it is used throughout your standard library library algorithm . For example, consider that there is an AlgoX algorithm that can be run much more efficiently on a container that provides random access (for example, vector ) than a container that provides bi-directional access ( list ). Thus, to select an algorithm based on the iterator type , one could use tag dispatch with iterator_traits
template <typename Iter> void AlgoXImpl(Iter first, Iter last, bidirectional_iterator_tag) { //.....Algo specialized to bidirectional iterators } template <typename Iter> void AlgoXImpl(Iter first, Iter last, random_access_iterator_tag) { //.....Algo specialized to random access iterators } template <typename Iter> void AlgoX(Iter first, Iter last) { if (first == last) return; AlgoXImpl(first, last, typename iterator_traits<Iter>::iterator_category()); }
As you can see, for the simple mind, this is nothing more than an example of operator overloading, since categories are essentially different types.
For a more real-world example, you can check how std::rotate implemented.
source share