please see the following code:
namespace std {
template <std::size_t I, class T>
auto& get(my_tuple_like_type<T>& t)
{
std::size_t ext = t.template extent<I>(); // This line
// .... do something with ext and return
}
}
As you can see, I'm trying to specialize (overload) std::get
to make my own class template my_tuple_like_type
somewhat std::tuple
-like.
But gcc 5.4.0 complains that the constant I
is not a type name. It seems that the reason is there is already a name std::extent
which is a class template.
A workaround I can think of is to forward the call to a free-standing implementation function declared outside namespace std
. But I wonder, is this the right behavior according to the standard? Or is it just another bug of gcc?
I guess this should be a bug, since clang and MSVC both compile the above code just fine. On the other hand, Nvidia's CUDA compiler (nvcc) produces a similar error message.
Thank you.
EDIT:
Providing overloads inside namespace std
is forbidden (Should you overload swap in the std namespace?), so I was doing a wrong thing.
But I can't see potential problems this may induce. Is there any reason why overloadings on user-defined types are forbidden?