c++11 - Why can't I specialize std::tuple_element? -
the following program attempts provide specialization std::tuple_element
user-defined type foo
. unfortunately, clang-3.5
rejects libc++, using other compilers or using other standard libraries clang-3.5
accept program. correct? if no, why not?
#include <utility> struct foo {}; namespace std { template<size_t, class> struct tuple_element; template<size_t i> struct tuple_element<i, foo> {}; } int main() { return 0; }
compiler output:
$ clang-3.5 -std=c++11 -stdlib=libc++ -lc++ test.cpp test.cpp:11:8: error: explicit specialization of non-template struct 'tuple_element' struct tuple_element<i, foo> {}; ^ ~~~~~~~~ 1 error generated. $ clang-3.5 -std=c++11 -lstdc++ test.cpp (no error) $ g++-4.9 -std=c++11 test.cpp (no error)
libc++
's entities in std::__1::
, inline namespace inside std
. own forward declaration template<size_t, class> struct tuple_element;
declares different class template, , partial specialization blows due ambiguity (though error message misleading).
remove forward declaration , should work.
Comments
Post a Comment