0
다른 튜플의 처음 n 개 요소에서 튜플을 생성하려고합니다. 이것은 내가 사용하는 재귀입니다 (여기서 유용한 것은 계산하지 않습니다).GCC에서이 템플릿 전문화가 작동하지 않는 이유는 무엇입니까?
이상하게도 g ++ 4.6.1을 사용하여 이해할 수 있지만 front<0,…>
은 front<n,…>
보다 특수하며 선택해야합니다. 이 버그입니까, 전문화에 대해 혼란 스럽습니까?
#include <tuple>
template<std::size_t, typename>
struct front;
#if 0
// This works, but I only want one case.
template<typename Head, typename... Tail>
struct front<0, std::tuple<Head, Tail...>> {
typedef std::tuple<> type;
};
template<typename Head>
struct front<0, std::tuple<Head>> {
typedef std::tuple<> type;
};
template<>
struct front<0, std::tuple<>> {
typedef std::tuple<> type;
};
#elseif 0
// this doesn't work, but I don't understand why:
// ambiguous class template instantiation, candidates are:
// struct front<0u, std::tuple<_Elements ...> >
// struct front<n, std::tuple<_Head, _Tail ...> >
template<typename... Tail>
struct front<0, std::tuple<Tail...>> {
typedef std::tuple<> type;
};
#else
// neither does this:
// ambiguous class template instantiation, candidates are:
// struct front<0u, T>
// struct front<n, std::tuple<_Head, _Tail ...> >
template<typename T>
struct front<0, T> {
typedef std::tuple<> type;
};
#endif
// this makes no sense, but it's short.
template<std::size_t n, typename Head, typename... Tail>
struct front<n, std::tuple<Head, Tail...>> {
typedef typename front<n - 1, std::tuple<Tail...>>::type type;
};
// check all cases, error includes calculated type:
front<0, std::tuple<int, float, double, long>>::type x0 = 0;
front<2, std::tuple<int, float, double, long>>::type x2 = 0;
front<4, std::tuple<int, float, double, long>>::type x4 = 0;