4
: 대신를 sizeof의 sizeof 연산자는 ...이 경우에 작동하기 때문에sizeof는 전문화를위한 템플릿 인수에 허용됩니까? 나는이 사용 GCC 4.7 스냅 샷의 라인을 따라 뭔가를 할 노력하고있어
template <int n, int... xs>
struct foo {
static const int value = 0;
};
// partial specialization where n is number of ints in xs:
template <int... xs>
struct foo<sizeof...(xs), xs...> { // error: template argument ‘sizeof (xs ...)’
// involves template parameter(s)
static const int value = 1;
};
template <int... xs>
struct foo<sizeof(xs), xs...> { // This compiles fine. sizeof(xs) is sizeof int
// even though packs aren't expanded
static const int value = 2;
};
오류가 이상하다. 둘 다 컴파일 시간 동안 쉽게 계산 될 수있는 것처럼 보입니다.
특수화를 위해 템플릿 인수에 sizeof...
을 사용할 수 없다는 컴파일러가 정확합니까?
'sizeof (xs)'의 의미는 무엇입니까? 확장되지 않은 팩에 대한 불만을 기대합니다. –
@ R.MartinhoFernandes 이상하게도 작동합니다. – Pubby
같은 오류, 간단한 코드 : http://ideone.com/BBKbw. 두 번째는 컴파일러 오류이거나 sizeof (xs) == sizeof (int)이므로 템플릿 인수를 포함하지 않을 수 있습니다. - 실용적인 솔루션으로서 :'value = sizeof ... (xs) == n;'? – UncleBens