Suppose you want to write a template function that accepts any specialization of std::vector?
What may work today may not work tomorrow.
On Writing Functions That Accept Any Specialization of a C++ Template Type
by Raymond Chen
From the article:
Suppose you want to write a template function that accepts any specialization of
std::vector
. Your first try would probably be something like this:template<typename Value> void accept_any_vector(std::vector<Value> v);However, this does not actually accept any vector specialization. There is a second template argument for the allocator, which has a default value that nearly everyone uses. But if somebody has a vector with a custom allocator, then your function won’t match.
Add a Comment
Comments are closed.