Subject: [boost] boost::optional - rvalue references
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2010-10-23 19:55:08


I have been looking to optimize my code using rvalue references when they are supported; however, I currently use boost::optional which does not know how to handle / forward rvalue references. In fact even the in_place() utilities do not work to forward the rvalue into the proper constructor.

My latest profiling shows that assigning a large vector to an optional is eating up 5% of my CPU time and I could replace this with a std::move() if boost::optional supported it.

I have attached an updated optional.hpp with the minimum changes necessary to support the following:

    test v ( 99 );
    test A ( 400 );
    boost::optional<test> i2(std::move(v));
    i2 = std::move(A);

Such that if test were a vector and 99 and 400 were the sizes, the end result is v & A are of size 0 and i2 is of size 400 and no copy constructors are called (only moves).

What is the plan for updating more of boost to take advantage of rvalue references?