|
Boost Users : |
Subject: Re: [Boost-users] [move] case study: simple cloning smart pointer
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2012-07-17 02:54:33
2012/7/16 Ion Gaztañaga <igaztanaga_at_[hidden]>
> El 16/07/2012 13:54, Krzysztof Czainski escribió:
>
>
> Version 1: C++03 vs. C++0x:
>> - the last 4 use cases {{{ ptr<A> b = make_b(); ptr<A> c( make_b() ); a
>> = make_a(); b = make_b(); }}} introduce a deep copy in version C++03,
>> while while the deep copy is avoided in C++0x.
>>
>
> Thanks for the report. It's a pity that current move emulation does not
> catch rvalues of convertible types to avoid the copy. Maybe for the last
> two cases you could try with BOOST_COPY_ASSIGN_REF(ptr<U>) to see if the
> deep copy is avoided.
>
> Best,
>
> Ion
>
Thanks for the suggestion, Ion. I had tried that before, but it caused
compiler errors. Replacing one line
operator=( ptr<U> const& b )
with
operator=( BOOST_COPY_ASSIGN_REF(ptr<U>) b )
results in compiler errors:
..\main.cpp:76:9: error: no match for 'operator=' in 'x = h'
..\/ptr.hpp:53:5: note: candidates are: ptr<T>& ptr<T>::operator=(ptr<T>&)
[with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:69:10: note: ptr<T>& ptr<T>::operator=(const
boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:77:10: note: ptr<T>&
ptr<T>::operator=(boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
..\main.cpp:88:9: error: no match for 'operator=' in 'b = make_b()()'
..\/ptr.hpp:53:5: note: candidates are: ptr<T>& ptr<T>::operator=(ptr<T>&)
[with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:69:10: note: ptr<T>& ptr<T>::operator=(const
boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
..\/ptr.hpp:77:10: note: ptr<T>&
ptr<T>::operator=(boost::rv<ptr<T> >&) [with T = A, ptr<T> = ptr<A>]
Regards
Kris
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net