Suppose I want to create a generic Serialize function that allows me to serialize built-in types, composed types and user-defined types. Then I see two ways to do it:
Overload based:
Serialize()
is overloaded for all (supported) builtin-types- function template overloads are added for vector/map/tuple which delegate to the Serialize overloads for the element types
- user-defined overloads are found with ADL
Class template specialization based:
- one single
Serialize
function that delegates toSerializeHelper<T>()::serialize(...)
SerializeHelper
is specialized for all built-in types- partial template specialization can be used to implement specialization for vector/map/tuple generically
- users can provide specializations for their own types
- one single
What would be the pros and cons of each approach?
Also how do they compare concerning compile-time performance?
Note: despite the similar title, this question is not a duplicate of Template Specialization VS Function Overloading because that question is about ADL vs function template specialization (and not class template specialization).