我正在使用g++-4.6.1 --std=c++0x
编译一段代码时出现了一个警告,但我无法理解它的含义,请帮忙看一下:
#include <vector>
#include <tuple>
int main()
{
std::tuple<std::vector<int>, int> t{ {1, 2, 3}, 10};
}
我收到了以下警告:
scratch.cpp: In function ‘int main()’:
scratch.cpp:6:55: warning: deducing ‘_U1’ as ‘std::initializer_list<int>’ [enabled by default]
/usr/local/include/c++/4.6.1/tuple:329:9: warning: in call to ‘std::tuple<_T1, _T2>::tuple(_U1&&, _U2&&) [with _U1 = std::initializer_list<int>, _U2 = int, _T1 = std::vector<int>, _T2 = int]’ [enabled by default]
scratch.cpp:6:55: warning: (you can disable this with -fno-deduce-init-list) [enabled by default]
看这个实现:
template<typename _T1, typename _T2>
class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
{
typedef _Tuple_impl<0, _T1, _T2> _Inherited;
public:
//...
template<typename _U1, typename _U2>
explicit
tuple(_U1&& __a1, _U2&& __a2)
: _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
//...
}
似乎这个警告是在抱怨它从
initializer_list<int>
(代码中的{1, 2, 3}
)转发到std::vector<int>
,后者将成为std::tuple
中的第一个类型。 对我来说,这似乎完全没问题。所以我的问题是:这个警告是什么意思?