As we have just seen, the Visitor pattern promotes separation of concerns; for example, the order of serialization and the mechanism of serialization are made independent, and a separate class is responsible for each. The pattern also simplifies code maintenance by collecting all code that performs a given task into one place. What the Visitor pattern does not promote is code reuse with no duplication. But that's the object-oriented Visitor pattern , before C++. Let's see what we can do with the generic capabilities of C++, starting from the regular Visitor pattern .
Visitors in modern C++
Generic Visitor
We are going to try to reduce the boilerplate code in the implementation of the Visitor pattern. Let's start...