I have a map:
typedef std::map<std::string, std::pair<std::vector<SomeObject>, std::future<boost::optional<uint64_t>>>> t_map;
t_map m;
When I insert in the map, I add a default constructed future to the pair:
...
std::future<boost::optional<uint64_t>> fut;
m.insert(t_map::value_type(mystring, std::make_pair(myvector, fut)));
Further on, I make a std::async call returning the future object which I then try to move to the pair:
auto record = m.find(somestring);
if (record != m.end())
{
std::future<boost::optional<uint64_t>> f = std::async(fn, args);
m->second.second(std::move(f));
}
However, I get the error:
error: no match for call to ‘(const std::future<boost::optional<long unsigned int> >) (std::remove_reference<std::future<boost::optional<long unsigned int> >&>::type)’
m->second.second(std::move(f));
I am not sure whats going wrong with this move semantics. Any advise?
UPDATE
I tried using operator= as Barry suggested, however I get the error no match to operator=. Why is the left hand operand being const qualified? I would have thought that the call will get resolved with the move assignment operator:
future& operator=(future&& __fut) noexcept
ERROR:
error: no match for ‘operator=’ (operand types are ‘const std::future<boost::optional<long unsigned int> >’ and ‘std::remove_reference<std::future<boost::optional<long unsigned int> >&>::type {aka std::future<boost::optional<long unsigned int> >}’)
m->second.second = std::move(f);
^
note: candidates are:
In file included from test.cpp:20:0:
/.../linux/x86-64/release/opt/gcc-4.9.1/include/c++/4.9.1/future:687:15: note: std::future<_Res>& std::future<_Res>::operator=(const std::future<_Res>&) [with _Res = boost::optional<long unsigned int>] <near match>
future& operator=(const future&) = delete;
^
note: no known conversion for implicit ‘this’ parameter from ‘const std::future<boost::optional<long unsigned int> >*’ to ‘std::future<boost::optional<long unsigned int> >*’
/.../linux/x86-64/release/opt/gcc-4.9.1/include/c++/4.9.1/future:689:15: note: std::future<_Res>& std::future<_Res>::operator=(std::future<_Res>&&) [with _Res = boost::optional<long unsigned int>] <near match>
future& operator=(future&& __fut) noexcept
^
note: no known conversion for implicit ‘this’ parameter from ‘const std::future<boost::optional<long unsigned int> >*’ to ‘std::future<boost::optional<long unsigned int> >*’