开发者

cannot create a unary tuple with an empty tuple in it (c++0x)

I was experimenting with tuples and encountered a problem with creating tuples. The code example is as follows.

//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;
}

I compiled it with both g++ 4.5 (g++ -std=c++0x a.cpp) and MS VC++2010. Both compilers are giving me an error on th开发者_开发技巧e second line in main().

My question is this: Since 'te' is a well-defined variable, why can't another tuple be created with te being the content. Is this semantic correct?

I guess this is kind of a boundary case, but if the arithmetic is correct, zero should be allowed, IMHO.

FYI, the error message from gcc is:

$ 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>&'


This looks like the compiler has matched your std::tuple<> against the following constructor of std::tuple<std::tuple<>> (See 20.4.2p15-17 in N3242):

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.

I think this is a bug in the implementation of std::tuple from your compiler; the "remark" implies that this constructor should not be considered, since it won't compile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜