How can I pass-through an r-value reference in VC++ 2013?

D

darylew

I'm starting out on Visual Studio 2013 Express on my Windows 8.1 Pro laptop
(upgraded from Windows 8 Pro and Vista). My code:

//=====
template < std::size_t I, typename T, std::size_t ...N >
inline BOOST_CONSTEXPR
auto get( array_md<T, N...> const &a ) BOOST_NOEXCEPT -> T const &
{
static_assert( I < array_md<T, N...>::static_size, "Index too large" );

return a.data()[ I ];
}

template < std::size_t I, typename T, std::size_t ...N >
inline
auto get( array_md<T, N...> &a ) BOOST_NOEXCEPT -> T &
{ return const_cast<T &>( get<I>(const_cast<array_md<T,N...> const &>( a ))); }

template < std::size_t I, typename T, std::size_t ...N >
inline
auto get( array_md<T, N...> &&a ) BOOST_NOEXCEPT -> T &&
{ return std::forward<T>( get<I>(a) ); }
//=====

The third overload gives me the following error:

//=====
1>------ Build started: Project: ArrayMD, Configuration: Debug Win32 ------
1> arraymd_test.cpp
1>c:\users\daryle\documents\github\arraymd\include\boost\container\array_md..hpp(1868): error C2440: 'return' : cannot convert from 'char [6]' to 'char(&&)[6]'
1> You cannot bind an lvalue to an rvalue reference
1> c:\users\daryle\documents\github\arraymd\test\arraymd_test.cpp(1179) : see reference to function template instantiation 'T (&&boost::container::get<0,char[6],>(boost::container::array_md<char [6],> &&))' being compiled
1> with
1> [
1> T=char [6]
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
//=====

I can't figure out a combination that makes VC++ like it. (Neither std::move or a direct static_cast<T&&> work.) Then I thought, "Does MS' implementation of tuple/pair/array's get skip the r-value overloads?". Checking it out, it does not (from <tuple>):

//=====
template<class _This,
class... _Rest>
struct tuple_element<0, tuple<_This, _Rest...> >
{ // select first element
typedef _This type;
typedef typename add_lvalue_reference<const _This>::type _Ctype;
typedef typename add_lvalue_reference<_This>::type _Rtype;
typedef typename add_rvalue_reference<_This>::type _RRtype;
typedef tuple<_This, _Rest...> _Ttype;
};

//...

template<size_t _Index,
class... _Types> inline
typename tuple_element<_Index, tuple<_Types...> >::_RRtype
get(tuple<_Types...>&& _Tuple)
{ // get rvalue reference to _Index element of tuple
typedef typename tuple_element<_Index, tuple<_Types...> >::_Ttype
_Ttype;
typedef typename tuple_element<_Index, tuple<_Types...> >::_RRtype
_RRtype;
return (_STD forward<_RRtype>(((_Ttype&)_Tuple)._Myfirst._Val));
}
//=====

I can't figure out how to adapt this. Help.

Daryle W.
 
Ö

Öö Tiib

I'm starting out on Visual Studio 2013 Express on my Windows 8.1 Pro laptop
(upgraded from Windows 8 Pro and Vista). My code:
snip

The third overload gives me the following error:
....

1>c:\users\daryle\documents\github\arraymd\include\boost\container\array_md.hpp(1868): error C2440: 'return' : cannot convert from 'char [6]' to 'char (&&)[6]'

You seemingly attempt something for what 'boost::container::array_md'
is not meant for. It is apparently not meant for providing rvalue
references to its elements.
I can't figure out how to adapt this. Help.

May be write your own array that does support such strange thing then.
 
D

darylew

I'm starting out on Visual Studio 2013 Express on my Windows 8.1 Pro laptop
(upgraded from Windows 8 Pro and Vista). My code:
snip

The third overload gives me the following error:

...
1>c:\users\daryle\documents\github\arraymd\include\boost\container\array_md.hpp(1868): error C2440: 'return' : cannot convert from 'char [6]' to 'char (&&)[6]'

You seemingly attempt something for what 'boost::container::array_md'
is not meant for. It is apparently not meant for providing rvalue
references to its elements.

I am attempting something that is supposed to be possible. I know this
because...
May be write your own array that does support such strange thing then.

....I AM the writer of array_md! And I am trying to write an r-value overload
for get, just like the Standard library has. My feat works just fine with GCC
(4.7 and 4.8, MinGW versions). I just can't get it to work in MSVC. I know
it's possible because MS's own libraries have r-value overloads for get. So why
doesn't my version work?
 
A

Alf P. Steinbach

I'm starting out on Visual Studio 2013 Express on my Windows 8.1 Pro laptop
(upgraded from Windows 8 Pro and Vista). My code:
snip

The third overload gives me the following error:
...

1>c:\users\daryle\documents\github\arraymd\include\boost\container\array_md.hpp(1868): error C2440: 'return' : cannot convert from 'char [6]' to 'char (&&)[6]'

You seemingly attempt something for what 'boost::container::array_md'
is not meant for. It is apparently not meant for providing rvalue
references to its elements.

I am attempting something that is supposed to be possible. I know this
because...
May be write your own array that does support such strange thing then.

...I AM the writer of array_md! And I am trying to write an r-value overload
for get, just like the Standard library has. My feat works just fine with GCC
(4.7 and 4.8, MinGW versions). I just can't get it to work in MSVC. I know
it's possible because MS's own libraries have r-value overloads for get. So why
doesn't my version work?

Please provide a complete minimum example that exhibits the problem.

Something one can compile.


Cheers,

- Alf
 
Ö

Öö Tiib

I'm starting out on Visual Studio 2013 Express on my Windows 8.1 Pro laptop
(upgraded from Windows 8 Pro and Vista). My code:
snip

The third overload gives me the following error:

...
1>c:\users\daryle\documents\github\arraymd\include\boost\container\array_md.hpp(1868): error C2440: 'return' : cannot convert from 'char [6]' to'char (&&)[6]'

You seemingly attempt something for what 'boost::container::array_md'
is not meant for. It is apparently not meant for providing rvalue
references to its elements.

I am attempting something that is supposed to be possible. I know this
because...

Yes, you already said you know it because 'std::get' works with 'std::array' and 'std::tuple'.
...I AM the writer of array_md! And I am trying to write an r-value overload
for get, just like the Standard library has. My feat works just fine with GCC
(4.7 and 4.8, MinGW versions). I just can't get it to work in MSVC. I know
it's possible because MS's own libraries have r-value overloads for get. So why
doesn't my version work?

Yes you have posted that the error is at line 1868 of array_md.hpp
that you maintain. So now write some own array that has same difficulty
exposed. It is likely that we discover a defect in MSVC of VS 2013 or that
we discover defect in your code or both or neither. Very interesting on all
the cases but ...
right now we can't help since we do not have enough information. :(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top