Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2003-01-31 12:00:27


On Friday, January 31, 2003, at 10:59 AM, David B. Held wrote:

> "Howard Hinnant" <hinnant_at_[hidden]> wrote in message
> news:95330DAA-352E-11D7-9A0A-003065D18932_at_twcny.rr.com...
>> [...]
>> I presented code under the thread "SmartPtr (Loki) - auto_ptr/move
>> c'tor issue" on Jan. 28 which does this. For easy reference, here is
>> the code again, slightly improved:
>>
>> http://home.twcny.rr.com/hinnant/Utilities/move_ptr
>> [...]
>
> This looks suspiciously like Mojo.

<big laugh> Well, Mojo looks suspiciously like auto_ptr! :-)

> Could you describe the differences?
> Or would you say that Mojo also achieves the same goals? I would
> like to support Mojo in SmartPtr, but I think we would all like to help
> people not abuse it.

I haven't looked at Mojo in a few weeks
(http://www.cuj.com/experts/2102/alexandr.htm?topic=experts), which is
long enough for my limited mental cache to flush. But when I did look
at it, I noted that it looked like a generalized auto_ptr design.
Andrei can correct me if I'm wrong.

Whether we're talking about Mojo, or the move_ptr presented, or
auto_ptr, one can play these games with auto_ptr_ref-like objects and
converting operators. Like Greg Colvin has said, all you have to do is:

> exploiting a
> loophole on a loophole, which I don't think should be imitated
> unless really, really necessary.

:-)

I would hope that any object built in this pattern would be a statement
that: Yes, we do need and want standardized move syntax/semantics.
No, we can't get there 100% with C++98, and the contortions necessary
to achieve what we can are overly complex and subtle. And really the
main point I've been trying to drive home is:

        *******************************************************
        * *
        * Do not move from an lvalue with copy syntax. *
        * *
        *******************************************************

Doing so will turn compile time errors into run time errors (as shown
earlier in this thread).

To implement the sample C++98 move_ptr, I literally started with
auto_ptr source and just disabled the "copy" from lvalue by making it
private, and then shook what was left around until it passed a few
simple unit tests. It is just a proof of concept that you don't have
to move with copy syntax in C++98.

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk