以下代码在g ++中编译时没有问题:
#include <iostream>
#include <string>
#include <tuple>
template<typename T>
void test(const T& value)
{
std::tuple<int, double> x;
std::cout << std::get<value>(x);
}
int main() {
test(std::integral_constant<std::size_t,1>());
}
Run Code Online (Sandbox Code Playgroud)
我使用了这个命令:
g++ test.cpp -o test -std=c++14 -pedantic -Wall -Wextra
Run Code Online (Sandbox Code Playgroud)
但是当我切换g++到clang++(使用g ++ 5.1.0和clang ++ 3.6.0)时,我收到以下错误:
test.cpp:9:18: error: no matching function for call to 'get'
std::cout << std::get<value>(x);
^~~~~~~~~~~~~~~
test.cpp:13:5: note: in instantiation of function template specialization 'test<std::integral_constant<unsigned long, 1> >' requested here
test(std::integral_constant<std::size_t,1>());
^~~~~~~~~~~~~~~
<skipped>
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.1.0/../../../../include/c++/5.1.0/tuple:867:5: note: candidate template ignored: …Run Code Online (Sandbox Code Playgroud)