This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[c++0x] std::tuple<MoveOnlyType>
- From: "Pedro LamarÃo" <pedro dot lamarao at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 12 Feb 2008 17:33:37 -0200
- Subject: [c++0x] std::tuple<MoveOnlyType>
- References: <d9cb29060802121129r124ae412m6792ab37e9f7310a@mail.gmail.com>
My understanding is that the following code should compile.
#ifndef __GXX_EXPERIMENTAL_CXX0X__
# error "This translation unit requires C++0x"
#endif
#include <tuple>
#include <utility>
struct MoveOnly {
MoveOnly () { }
MoveOnly (MoveOnly&&) { }
MoveOnly& operator= (MoveOnly&&) { return *this; }
private:
MoveOnly (MoveOnly const&); // = delete
MoveOnly& operator= (MoveOnly const&); // = delete
};
MoveOnly
make_move_only () { return MoveOnly(); }
int
main (int argc, char* argv[]) {
typedef std::tuple<MoveOnly, MoveOnly> move_only_tuple;
move_only_tuple t1(make_move_only(), make_move_only());
move_only_tuple t2(std::move(t1));
return 0;
}
Am I missing something?
I'm using gcc version:
[psilva@desen cxx]$ g++-4.3 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.3-20080208/configure --prefix=/opt/gcc-4.3
--enable-languages=c,c++
Thread model: posix
gcc version 4.3.0 20080208 (experimental) (GCC)
I get the following error:
[psilva@desen cxx]$ make
g++-4.3 --std=c++0x -O0 main.cpp -o main
main.cpp: In copy constructor 'std::_Head_base<0, MoveOnly,
true>::_Head_base(const std::_Head_base<0, MoveOnly, true>&)':
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:66:
instantiated from 'std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with
int _Idx = 0, _Head = MoveOnly, _Tail = MoveOnly]'
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:294:
instantiated from 'std::tuple<_T1, _T2>::tuple(std::tuple<_T1,
_T2>&&) [with _T1 = MoveOnly, _T2 = MoveOnly]'
main.cpp:29: instantiated from here
main.cpp:17: 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:66:
error: within this context
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:
In constructor 'std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with
int _Idx = 0, _Head = MoveOnly, _Tail = MoveOnly]':
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:160:
note: synthesized method 'std::_Head_base<0, MoveOnly,
true>::_Head_base(const std::_Head_base<0, MoveOnly, true>&)' first
required here
main.cpp: 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 = MoveOnly]'
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:288:
instantiated from 'std::tuple<_T1, _T2>::tuple(_U1&&, _U2&&) [with
_U1 = MoveOnly, _U2 = MoveOnly, _T1 = MoveOnly, _T2 = MoveOnly]'
main.cpp:28: instantiated from here
main.cpp:17: 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
main.cpp: In copy constructor 'std::_Head_base<1, MoveOnly,
true>::_Head_base(const std::_Head_base<1, MoveOnly, true>&)':
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:66:
instantiated from 'std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with
int _Idx = 1, _Head = MoveOnly, _Tail = ]'
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:160:
instantiated from 'std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with
int _Idx = 0, _Head = MoveOnly, _Tail = MoveOnly]'
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:294:
instantiated from 'std::tuple<_T1, _T2>::tuple(std::tuple<_T1,
_T2>&&) [with _T1 = MoveOnly, _T2 = MoveOnly]'
main.cpp:29: instantiated from here
main.cpp:17: 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:66:
error: within this context
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:
In constructor 'std::_Tuple_impl<_Idx, _Head, _Tail
...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with
int _Idx = 1, _Head = MoveOnly, _Tail = ]':
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:160:
note: synthesized method 'std::_Head_base<1, MoveOnly,
true>::_Head_base(const std::_Head_base<1, MoveOnly, true>&)' first
required here
main.cpp: In constructor 'std::_Head_base<_Idx, _Head,
true>::_Head_base(typename std::__add_c_ref<_Head>::type) [with int
_Idx = 1, _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 = 1, _Head =
MoveOnly, _Tail = ]'
/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 = MoveOnly]'
/opt/gcc-4.3/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/tuple:288:
instantiated from 'std::tuple<_T1, _T2>::tuple(_U1&&, _U2&&) [with
_U1 = MoveOnly, _U2 = MoveOnly, _T1 = MoveOnly, _T2 = MoveOnly]'
main.cpp:28: instantiated from here
main.cpp:17: 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: ** [main] Erro 1
I've looked inside the tuple implementation and the compiler seems to
select this constructor:
_Head_base(typename __add_c_ref<_Head>::type __h)
: _Head(__h) { }
instead of this one:
_Head_base(typename std::remove_reference<_Head>::type&& __h)
: _Head(std::forward<_Head>(__h)) { }
for some reason I don't understand.
--
Pedro LamarÃo
"The True Self is the meaning of the True Will:
know thyself through Thy Way."
-- The Book of Thoth
--
Pedro LamarÃo
"The True Self is the meaning of the True Will:
know thyself through Thy Way."
-- The Book of Thoth