[utility] rvalue support in value_initialized

Hi everybody! Recently I encountered a problem using the std:::unique_ptr within boost::spirit. The reason is apparently that value_initialized does not support rvalue assignment. Are there any plans to implement move semantics into value_initialized? Mainly I would be interested in making something like this work: std::unique_ptr<T> a= boost::get( boost::value_initialized< std::unique_ptr<T> >() ); Currently this fails due to the fact, that unique_ptr can be moved but not copied. Regards Claas

on Wed Sep 14 2011, "Claas H. Köhler" <claas.koehler-AT-dlr.de> wrote:
Hi everybody!
Recently I encountered a problem using the std:::unique_ptr within boost::spirit. The reason is apparently that value_initialized does not support rvalue assignment. Are there any plans to implement move semantics into value_initialized? Mainly I would be interested in making something like this work:
std::unique_ptr<T> a= boost::get( boost::value_initialized< std::unique_ptr<T> >() );
Currently this fails due to the fact, that unique_ptr can be moved but not copied.
No plans as far as I know, but I'm sure a patch would be welcome. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

Principially I would like to contribute. I have to admit though, that I have never contributed to boost before. In my oppinion it should suffice to add move constructors/ move assignment to /utility/value_init.hpp, which I could do. How do we go on from there? Shall I submit the modified header file to this mailing list for review or what is the usual procedure? Regards Claas On 09/14/2011 06:06 PM, Dave Abrahams wrote:
on Wed Sep 14 2011, "Claas H. Köhler"<claas.koehler-AT-dlr.de> wrote:
Hi everybody!
Recently I encountered a problem using the std:::unique_ptr within boost::spirit. The reason is apparently that value_initialized does not support rvalue assignment. Are there any plans to implement move semantics into value_initialized? Mainly I would be interested in making something like this work:
std::unique_ptr<T> a= boost::get( boost::value_initialized< std::unique_ptr<T> >() );
Currently this fails due to the fact, that unique_ptr can be moved but not copied.
No plans as far as I know, but I'm sure a patch would be welcome.

On Sep 15, 2011, at 3:34 AM, Claas H. Köhler wrote:
Principially I would like to contribute. I have to admit though, that I have never contributed to boost before.
To start out, please do not top-post. ;)
In my oppinion it should suffice to add move constructors/ move assignment to /utility/value_init.hpp, which I could do.
How do we go on from there? Shall I submit the modified header file to this mailing list for review or what is the usual procedure?
Yes, you should work with the list and the owner/maintainer of the library, who appears to be Fernando Cacciola according to the doc. I am no rvalue expert but you should either use Boost.Move or at least guard your code with the right #ifdef so that you're not breaking the library for everyone stuck with c++03. Hopefully others more experienced can help you with that. Cheers, Gordon

[reordering; please see http://www.boost.org/community/policy.html#quoting] 2011/9/15 "Claas H. Köhler" <claas.koehler@dlr.de>
On 09/14/2011 06:06 PM, Dave Abrahams wrote:
on Wed Sep 14 2011, "Claas H. Köhler"<claas.koehler-AT-dlr.**de<http://claas.koehler-AT-dlr.de>> wrote:
Hi everybody!
Recently I encountered a problem using the std:::unique_ptr within boost::spirit. The reason is apparently that value_initialized does not support rvalue assignment. Are there any plans to implement move semantics into value_initialized? Mainly I would be interested in making something like this work:
std::unique_ptr<T> a= boost::get( boost::value_initialized< std::unique_ptr<T> >() );
Currently this fails due to the fact, that unique_ptr can be moved but not copied.
No plans as far as I know, but I'm sure a patch would be welcome.
Principially I would like to contribute. I have to admit though, that I
have never contributed to boost before.
In my oppinion it should suffice to add move constructors/ move assignment to /utility/value_init.hpp, which I could do.
How do we go on from there? Shall I submit the modified header file to this mailing list for review or what is the usual procedure?
I'm guessing it would probably be sufficient to submit a patch to an open trac ticket (filed as a feature request). Documentation patches would probably also be in order. I think a big win would be to use Ion G's Boost.Move library to implement the move constructor and move assignment operator. I *believe* this is slated to be included with 1.48, but that's entirely up to Ion on whether it's ready yet. - Jeff

On 14/09/2011 15:00, "Claas H. Köhler" wrote:
Hi everybody!
Recently I encountered a problem using the std:::unique_ptr within boost::spirit. The reason is apparently that value_initialized does not support rvalue assignment. Are there any plans to implement move semantics into value_initialized? Mainly I would be interested in making something like this work:
std::unique_ptr<T> a= boost::get( boost::value_initialized< std::unique_ptr<T> >() );
Currently this fails due to the fact, that unique_ptr can be moved but not copied.
I had a patch for this and for fusion in order to make spirit move-enabled.

On 9/18/2011 1:45 AM, Mathias Gaunard wrote:
On 14/09/2011 15:00, "Claas H. Köhler" wrote:
Hi everybody!
Recently I encountered a problem using the std:::unique_ptr within boost::spirit. The reason is apparently that value_initialized does not support rvalue assignment. Are there any plans to implement move semantics into value_initialized? Mainly I would be interested in making something like this work:
std::unique_ptr<T> a= boost::get( boost::value_initialized< std::unique_ptr<T> >() );
Currently this fails due to the fact, that unique_ptr can be moved but not copied.
I had a patch for this and for fusion in order to make spirit move-enabled.
Where is it? Was it submitted? Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com

On 19/09/2011 05:14, Joel de Guzman wrote:
Where is it? Was it submitted?
I sent it to several people by email a long time ago, you included. I don't think it was ever applied. Christopher Schmidt said he was fixing problems by the end of the week but I never got news of him. Anyway, the bit for value_initialized is the following: Index: boost/utility/value_init.hpp =================================================================== --- boost/utility/value_init.hpp (révision 69204) +++ boost/utility/value_init.hpp (copie de travail) @@ -22,7 +22,7 @@ // contains. More details on these issues are at libs/utility/value_init.htm #include <boost/aligned_storage.hpp> -#include <boost/config.hpp> // For BOOST_NO_COMPLETE_VALUE_INITIALIZATION. +#include <boost/config.hpp> // For BOOST_NO_COMPLETE_VALUE_INITIALIZATION and BOOST_NO_RVALUE_REFERENCES. #include <boost/detail/workaround.hpp> #include <boost/static_assert.hpp> #include <boost/type_traits/cv_traits.hpp> @@ -30,6 +30,9 @@ #include <boost/swap.hpp> #include <cstring> #include <new> +#ifndef BOOST_NO_RVALUE_REFERENCES +#include <utility> +#endif #ifdef BOOST_MSVC #pragma warning(push) @@ -169,7 +172,23 @@ return x.data() ; } +#ifndef BOOST_NO_RVALUE_REFERENCES + template<class T> +T&& get ( initialized<T>&& x ) +{ + return std::move(x.data()) ; +} + +template<class T> +T const&& get ( const initialized<T>&& x ) +{ + return std::move(x.data()) ; +} + +#endif + +template<class T> void swap ( initialized<T> & lhs, initialized<T> & rhs ) { lhs.swap(rhs) ; @@ -229,7 +248,23 @@ return x.data() ; } +#ifndef BOOST_NO_RVALUE_REFERENCES + template<class T> +T&& get ( value_initialized<T>&& x ) +{ + return std::move(x.data()) ; +} + +template<class T> +T const&& get ( const value_initialized<T>&& x ) +{ + return std::move(x.data()) ; +} + +#endif + +template<class T> void swap ( value_initialized<T> & lhs, value_initialized<T> & rhs ) { lhs.swap(rhs) ; Note however that it assumes that if BOOST_NO_RVALUE_REFERENCES is not set, then you have std::move in <utility>, which isn't the case with certain compilers.

Mathias Gaunard <mathias.gaunard@ens-lyon.org> writes:
On 19/09/2011 05:14, Joel de Guzman wrote:
Where is it? Was it submitted?
I sent it to several people by email a long time ago, you included. I don't think it was ever applied. Christopher Schmidt said he was fixing problems by the end of the week but I never got news of him.
[...] Oops, your patch must have slipped my attention. Could you please send it again? Christopher

+#ifndef BOOST_NO_RVALUE_REFERENCES + template<class T> +T&& get ( value_initialized<T>&& x ) +{ + return std::move(x.data()) ; +} ... +#endif
Mathias Gaunard wrote:
Note however that it assumes that if BOOST_NO_RVALUE_REFERENCES is not set, then you have std::move in <utility>, which isn't the case with certain compilers.
In order to avoid such a dependency on <utility>, I would suggest to do static_cast<T&&>(x.data()), instead of std::move(x.data()). My two cents, Niels -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center
participants (8)
-
"Claas H. Köhler"
-
Christopher Schmidt
-
Dave Abrahams
-
Gordon Woodhull
-
Jeffrey Lee Hellrung, Jr.
-
Joel de Guzman
-
Mathias Gaunard
-
Niels Dekker - address until 2014