template<std::size_t sz>
constexpr std::array<int,sz> range(){
std::array<int,sz> arr{0};
std::iota(arr.begin(),arr.end(),0);
return arr;
}
나는 다음과 같은 오류컴파일 타임에 어떻게 배열을 만드나요?
> $ clang++ -stdlib=libc++ -std=c++1y main.cpp -o main && ./main
main.cpp:33:30: error: implicit instantiation of undefined template 'std::__1::array<int, 10>'
constexpr std::array<int,sz> range(){
^
main.cpp:48:12: note: in instantiation of function template specialization 'range<10>' requested here
auto r = range<10>();
^
/usr/include/c++/v1/__tuple:69:65: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY array;
^
main.cpp:34:22: error: implicit instantiation of undefined template 'std::__1::array<int, 10>'
std::array<int,sz> arr{0};
^
/usr/include/c++/v1/__tuple:69:65: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY array;
^
main.cpp:48:12: error: implicit instantiation of undefined template 'std::__1::array<int, 10>'
auto r = range<10>();
^
/usr/include/c++/v1/__tuple:69:65: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TYPE_VIS_ONLY array;
^
3 errors generated.
내 실수는 무엇인가를 얻을 수 있습니다
auto r = range<10>()
과 같이 호출하려고하면?
포함합니다. –
함수는 C++ 11에서 컴파일 타임 실행에 적용되지 않습니다. – chris
@chris하지만 C++ 14에서는 제대로 작동할까요? –