View Single Post
  #7 (permalink)  
Old 05-21-2012, 07:53 AM
Joshua Maurice
Guest
 
Posts: n/a
Default Re: Broken interaction between std::priority_queue and move-onlytypes

On May 20, 9:19 pm, Zoltan Juhasz <zoltan.juh...@gmail.com> wrote:
> On Sunday, 20 May 2012 10:48:09 UTC-4, Joshua Maurice wrote:
> > Why not
> > value_type&& pop2()
> > or something?
> > (Insert whatever magic syntax to make this actually work. Sorry, I'm
> > still new to move-stuff.)
> > (As for the name "pop2" - I'm sorry, but I suck at naming.)

>
> The problem with returning rvalue reference - or any reference as
> a matter of fact - that you have to be able to store the object, on
> which you return a reference to, someplace that outlives
> the function-call.
>
> For example this code introduces a dangling reference:
>
> value_type&& bad_pop()
> {
> auto e = { move_if_noexcept( internal_top() ) };
> internal_pop();
> return e; // oops, reference returned to temporary
>
> }


I see. I need more work with move types. I haven't had a chance to
play around with them yet. I spoke too soon.

I do like your
pop(value_type& );
now.

Thanks for your explanation.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Reply With Quote