I wonder whether something along these lines would be possible: (assuming availability of template lambdas)
void some_func() { template<typename T> std::map<int, T> storage; auto store = []<typename T>(int key, const T& value) { storage<T>[key] = value; }; store(0, 2); store(1, "Hello"s); store(2, 0.7); // All three values are stored in a different map, according to their type. }
Now, is this useful?
As a simpler use, notice that the initialization of pi<T>
uses explicit conversion (explicit call of a unary constructor) and not uniform initialization. Which means that, given a type radians
with a constructor radians(double)
, you can write pi<radians>
.