此代码使用 GCC 13 和 Clang 17 可以正常编译和执行,但无法在 MSVC 上编译。我想知道代码是否需要按照标准工作,或者这是否是 MSVC 的问题。 演示
#include <utility>
#include <iostream>
enum e : int { A=5, B, C, D };
auto x = std::integer_sequence<e, A, B, C, D>{};
auto y = std::integer_sequence<unsigned, 9, 4, 3, 8>{};
auto z = std::integer_sequence<int, 0, 1, 2, 3>{};
template<typename T, T... ints>
void print_sequence(std::integer_sequence<T, ints...> int_seq)
{
std::cout << "The sequence of size " << int_seq.size() << ": ";
((std::cout << ints << ' '), ...);
std::cout << '\n';
}
int main(int, char**)
{
print_sequence(x);
print_sequence(y);
print_sequence(z);
return 0;
}
MSVC 给出此错误:
错误 C2338:static_assert 失败:“integer_sequence
MSVC 是对的。来自 [intseq.intseq]:
namespace std { template<class T, T... I> struct integer_sequence { using value_type = T; static constexpr size_t size() noexcept { return sizeof...(I); } }; }
授权:
是整数类型。T