This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [c++0x] std::tuple<MoveOnlyType>


2008/2/12, Pedro LamarÃo <pedro.lamarao@gmail.com>:
> My understanding is that the following code should compile.

This is a somewhat smaller version of the same thing.

[psilva@desen cxx]$ cat MoveOnly.hpp
#ifndef MOVEONLY_HPP
#define MOVEONLY_HPP

struct MoveOnly {

        MoveOnly () { }

        MoveOnly (MoveOnly&&) { }

        MoveOnly& operator= (MoveOnly&&) { return *this; }

private:
        MoveOnly (MoveOnly const&); // = delete
        MoveOnly& operator= (MoveOnly const&); // = delete
};

inline
MoveOnly
make_move_only () { return MoveOnly(); }

#endif

[psilva@desen cxx]$ cat rvalue_tuple.cpp
#include <tuple>
#include <utility>

#include "MoveOnly.hpp"

int
main (int argc, char* argv[]) {

    typedef std::tuple<MoveOnly> tuple_t;
    tuple_t t1(make_move_only());

    return 0;
}

[psilva@desen cxx]$ make
g++-4.3 --std=c++0x -O0 -I.    rvalue_tuple.cpp   -o rvalue_tuple
MoveOnly.hpp: In constructor 'std::_Head_base<_Idx, _Head,
true>::_Head_base(typename std::__add_c_ref<_Head>::type) [with int
_Idx = 0, _Head = MoveOnly]':
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:146:
  instantiated from 'std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(typename std::__add_c_ref<_Head>::type, typename
std::__add_c_ref<_Tail>::type ...) [with int _Idx = 0, _Head =
MoveOnly, _Tail = ]'
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:222:
  instantiated from 'std::tuple<_Elements>::tuple(_UElements&& ...)
[with _UElements = MoveOnly, _Elements = MoveOnly]'
rvalue_tuple.cpp:10:   instantiated from here
MoveOnly.hpp:13: error: 'MoveOnly::MoveOnly(const MoveOnly&)' is private
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:76:
error: within this context
make: ** [rvalue_tuple] Erro 1


I've noticed that the problem is actually happening in _Tuple_impl.

This constructor:

      template<typename _UHead, typename... _UTail>
        explicit
        _Tuple_impl(typename std::remove_reference<_UHead>::type&& __head,
                    typename std::remove_reference<_UTail>::type&&... __tail)

is never entering the overload candidate set for _UHead = MoveOnly and
_UTail = "empty".

When I comment out the declaration of this constructor:

      explicit
      _Tuple_impl(typename __add_c_ref<_Head>::type __head,
                  typename __add_c_ref<_Tail>::type... __tail)

the compiler gives me this overload candidate list:

[psilva@desen cxx]$ make
g++-4.3 --std=c++0x -O0 -I.    rvalue_tuple.cpp   -o rvalue_tuple
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:
In constructor 'std::tuple<_Elements>::tuple(_UElements&& ...) [with
_UElements = MoveOnly, _Elements = MoveOnly]':
rvalue_tuple.cpp:10:   instantiated from here
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:222:
error: no matching function for call to 'std::_Tuple_impl<0,
MoveOnly>::_Tuple_impl(MoveOnly)'
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:158:
note: candidates are: std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with
int _Idx = 0, _Head = MoveOnly, _Tail = ]
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:155:
note:                 std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(const std::_Tuple_impl<_Idx, _Head, _Tail ...>&)
[with int _Idx = 0, _Head = MoveOnly, _Tail = ]
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:140:
note:                 std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl() [with int _Idx = 0, _Head = MoveOnly, _Tail = ]
make: ** [rvalue_tuple] Erro 1

-- 
 Pedro LamarÃo

 "The True Self is the meaning of the True Will:
   know thyself through Thy Way."
                                        -- The Book of Thoth

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]