无法创建一个空元组的一元组(c 0x)

我正在尝试元组,并遇到一个创建元组的问题.
代码示例如下.
//a.cpp
#include <tuple>
using namespace std;

int main() {
  auto te = make_tuple();    //this line is ok
  auto tte = make_tuple(te); //this line gives an error.
  return 0;
}

我用g 4.5(g -std = c 0x a.cpp)和MS VC 2010编译它.
两个编译器都在main()中的第二行给我一个错误.

我的问题是这样的:
由于’te’是一个明确定义的变量,为什么不能用te作为内容来创建另一个元组.这个语义是否正确?

我想这是一种边界的情况,但是如果算术是正确的,应该允许零.

来自gcc的错误消息是:

$gcc -std=c++0x a.cpp

In file included from a.cpp:1:0:
c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++/tuple: In constructor
  'std::tuple<_Elements>::tuple(std::tuple<_UElements ...>&) [with _UElements = {},_Elements = {std::tuple<>}]':

c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++/tuple:551:62:   instantiated from
  'std::tuple<typename std::__decay_and_strip<_Elements>::__type ...> 
  std::make_tuple(_Elements&& ...) [with _Elements = {std::tuple<>&},typename
  std::__decay_and_strip<_Elements>::__type = <type error>]'
a.cpp:6:27:   instantiated from here

c:\mingw\bin\../lib/gcc/mingw32/4.5.2/include/c++/tuple:259:70: error: invalid
  static_cast from type 'std::tuple<>' to type 'const std::_Tuple_impl<0u>&'

解决方法

这看起来像编译器已经匹配了你的std :: tuple<>反对std :: tuple< std :: tuple>的以下构造函数(见N3242中的20.4.2p15-17):

template <class... UTypes> tuple(const tuple<UTypes...>& u);

Requires:
sizeof...(Types) == sizeof...(UTypes).
is_constructible<Ti,const Ui &>::value is true for all i.

Effects:
Constructs each element of *this with
the corresponding element of u.

Remark: This constructor shall not
participate in overload resolution
unless const Ui & is implicitly
convertible to Ti for all i.

我认为这是编译器执行std :: tuple的一个bug; “注释”意味着这个构造函数不应该被考虑,因为它不会被编译.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...