【发布时间】:2018-10-28 23:42:32
【问题描述】:
考虑这段代码:
std::vector<
std::tuple<std::vector<std::size_t>,
std::vector<std::size_t>,
std::vector<std::size_t>>
> foo = {
{{2, 1, 2, 3}, {1, 2}, {2, 3}},
{{2, 3, 4, 0}, {3}, {2, 3, 4}},
{{2, 3, 4, 0}, {0}, {3, 4, 0}},
};
在 Clang 和 GCC 6 或更高版本中,它编译得很好。在 GCC 5.5 中它给出了这个错误:
In function 'int main()':
:16:4: error: converting to
'std::tuple<std::vector<long unsigned int, std::allocator<long unsigned int> >,
std::vector<long unsigned int, std::allocator<long unsigned int> >,
std::vector<long unsigned int, std::allocator<long unsigned int> > >'
from initializer list would use explicit constructor
'constexpr std::tuple< <template-parameter-1-1> >::tuple(const _Elements& ...)
[with _Elements = {
std::vector<long unsigned int, std::allocator<long unsigned int> >, std::vector<long unsigned int, std::allocator<long unsigned int> >, std::vector<long unsigned int, std::allocator<long unsigned int> >}]'
};
^
为什么会这样,我该如何解决?
【问题讨论】:
-
IIRC GCC 5 系列默认使用 C++11,而 GCC 6 和 7 系列默认使用 C++14。 the
std::tupleconstructor 的标准之间也有一些变化。这些更改可能与您的问题有关。 -
@Someprogrammerdude 显然是that's not it。
-
See notes paragraph。这是 C++17 的一个特性。我猜在 GCC 6 中添加了对它的支持。
-
看起来这可能适合你:stackoverflow.com/questions/12436586/…
-
您可以通过显式调用所有构造函数来解决问题。