C++: Overloaded template alias
If you want to write a fancy conditional forwarder, you'll have to not just use using
.
template<class A, class B, class... C>
struct vector_map_helper {
using type = other_namespace::vector_map<A,B>;
};
// specialize for 3:
template<class A, class B, class C>
struct vector_map_helper<A,B,C> {
using type = other_namespace::vector_map<A,B,C>;
};
template<class A, class B, class C, class D, class...Z>
struct vector_map_helper<A,B,C,D, Z...>; // error 4 or more
template<class A, class B, class... C>
using vector_map = typename vector_map_helper<A,B,C...>::type;
in general, even if you are implementing a std
library, you should avoid adding any "user facing" interfaces to your std
that do not come from the std
library. And the stuff you do support should match std
specifications.
Have a nonstd
or a std_ext
namespace for non-std
extensions. This will both make existing code either fail to compile or work when ported over, and it will avoid training your programmer-users in bad habits about what is in std
.
It is also illegal to add most things to std
with narrow exceptions, like std::hash
specializations.