이 코드 고려 컴파일 실패부름
error: ‘* & xx’ is not a constant expression
note: in template argument for type ‘int’
다음 main()
함수에서
#include <array>
template < int... Ints >
constexpr std::array<int,sizeof...(Ints)> theIntArray = {Ints...};
template < size_t NN >
constexpr void test(const std::array<int,NN>& xx)
{
theIntArray<xx[0]>;
}
constexpr std::array<int,2> aa = {10,20};
int main()
{
theIntArray<aa[0]>; // passes
test(aa); // FAILS ?!
return 0;
}
을 두번째 라인 이상한 오류 메시지와 함께 실패 동안 첫번째 라인 패스 gcc-7.0.1을 사용 중이고 라이브 예제 here을 찾을 수 있습니다.
표준에 따른 것입니까, 아니면 버그입니까? 첫 번째 라인이 통과하는 동안 두 번째 라인이 실패하게 만드는 것은 무엇입니까?
TIL 리터럴 형식에 const-reference를 추가하여 사용자 정의 형식이 아닌 템플릿 매개 변수를 모방합니다. upvoted. – TemplateRex