设置-std = c ++ 17时,以下代码在g ++ 8.3和7.4中可以正常编译:
#include <any>
#include <tuple>
#include <vector>
int main()
{
std::vector<std::tuple<std::any>> f2;
f2.emplace_back(42);
return 0;
}
VS2017也很好用。
但是在g ++ 9.1中,我看到此错误:
In file included from /usr/include/c++/9/bits/move.h:55,
from /usr/include/c++/9/bits/nested_exception.h:40,
from /usr/include/c++/9/exception:144,
from /usr/include/c++/9/new:40,
from /usr/include/c++/9/any:37,
from a.cpp:1:
/usr/include/c++/9/type_traits: In instantiation of ‘struct std::__and_<std::is_constructible<std::tuple<std::any>, std::tuple<std::any>&&>, std::__is_nt_constructible_impl<std::tuple<std::any>, std::tuple<std::any>&&> >’:
/usr/include/c++/9/type_traits:974:12: required from ‘struct std::is_nothrow_constructible<std::tuple<std::any>, std::tuple<std::any>&&>’
/usr/include/c++/9/type_traits:1005:12: required from ‘struct std::__is_nothrow_move_constructible_impl<std::tuple<std::any>, true>’
/usr/include/c++/9/type_traits:1011:12: required from ‘struct std::is_nothrow_move_constructible<std::tuple<std::any> >’
/usr/include/c++/9/any:95:67: required by substitution of ‘template<class _Tp, class _Safe, bool _Fits> using _Internal = std::integral_constant<bool, (_Safe::value && _Fits)> [with _Tp = std::tuple<std::any>; _Safe = std::is_nothrow_move_constructible<std::tuple<std::any> >; bool _Fits = ((sizeof (std::tuple<std::any>) <= sizeof (std::any::_Storage)) && (8 <= 8))]’
/usr/include/c++/9/any:104:13: required by substitution of ‘template<class _Tp> using _Manager = std::conditional_t<std::any::_Internal<_Tp>::value, std::any::_Manager_internal<_Tp>, std::any::_Manager_external<_Tp> > [with _Tp = std::tuple<std::any>]’
/usr/include/c++/9/any:180:8: [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/c++/9/type_traits:925:12: required from ‘struct std::is_move_constructible<std::tuple<std::any> >’
/usr/include/c++/9/bits/alloc_traits.h:619:12: required from ‘struct std::__is_move_insertable<std::allocator<std::tuple<std::any> > >’
/usr/include/c++/9/bits/stl_vector.h:446:28: required from ‘static constexpr bool std::vector<_Tp, _Alloc>::_S_use_relocate() [with _Tp = std::tuple<std::any>; _Alloc = std::allocator<std::tuple<std::any> >]’
/usr/include/c++/9/bits/vector.tcc:459:44: required from ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {int}; _Tp = std::tuple<std::any>; _Alloc = std::allocator<std::tuple<std::any> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::tuple<std::any>*, std::vector<std::tuple<std::any> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::tuple<std::any>*]’
/usr/include/c++/9/bits/vector.tcc:121:4: required from ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int}; _Tp = std::tuple<std::any>; _Alloc = std::allocator<std::tuple<std::any> >; std::vector<_Tp, _Alloc>::reference = std::tuple<std::any>&]’
a.cpp:8:21: required from here
/usr/include/c++/9/type_traits:131:12: error: incomplete type ‘std::is_constructible<std::tuple<std::any>, std::tuple<std::any>&&>’ used in nested name specifier
131 | struct __and_<_B1, _B2>
| ^~~~~~~~~~~~~~~~
代码是否有问题或是g ++-9问题?