Why is std :: get <T> for `variant` a global function?
1 answer
If get<T>() was a member function template woudl keyword is needed when it is called in a dependent context. For instance:
template <typename Variant> void f(Variant const& v) { auto x0 = v.template get<T>(); // if it were a member auto x1 = get<T>(v); // using a non-member function } Even without a using declaration or get() directives, if found as std::variant<...> and get() , they are declared in the std . Thus, there seems to be no good reason to make it a member function, since a global function is easier to use.
+6