|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-01-09 14:55:23
David Abrahams wrote:
> hartmutkaiser_at_[hidden] (Hartmut Kaiser) writes:
>
>> David Abrahams wrote:
>>
>>>> Completely relying on MOJO or similar techniques would
>>> require, that
>>>> I'm able/allowed to _modify_ the base iterator code, which isn't
>>>> always true.
>>>
>>> I'm not talking about relying on MOJO, I'm talking about
>>> andrei's finding that on compilers that elide copies, passing
>>> objects by reference if they're just going to be copied
>>> anyway is almost always a mistake.
>>
>> Sorry, I've misunderstood.
>>
>> It seems to me, that Andrei wrote his 'Lying const' statements under
>> the strong impression, that ZUTO would work as expected. But AFAIR
>> ZUTO never worked as envisioned and therefor MOJO was developed. But
>> I'm not pushing you to use a const reference, it was merely a
>> question to understand the rationale behind this design decision.
>
> I don't feel pushed. I would like to do it, and have only one small
> reservation. If you could clear that matter up definitively I'd be
> very happy to make the change.
Enjoy:
#include <iostream>
struct X
{
X()
{
}
X(int)
{
}
X(X const &)
{
std::cout << "X(X const &)\n";
}
};
struct Y
{
X x_;
Y(X x): x_(x)
{
}
};
struct Y2
{
X x_;
Y2(X x);
};
struct Z
{
X x_;
Z(X const & x): x_(x)
{
}
};
struct Z2
{
X x_;
Z2(X const & x);
};
int main()
{
X x;
{
std::cout << "Y y(x);\n";
Y y(x);
}
{
std::cout << "Y y( (X()) )\n";
Y y( (X()) );
}
{
std::cout << "Y y(1)\n";
Y y(1);
}
{
std::cout << "Y2 y(x);\n";
Y2 y(x);
}
{
std::cout << "Y2 y( (X()) )\n";
Y2 y( (X()) );
}
{
std::cout << "Y2 y(1)\n";
Y2 y(1);
}
{
std::cout << "Z z(x);\n";
Z z(x);
}
{
std::cout << "Z z( (X()) )\n";
Z z( (X()) );
}
{
std::cout << "Z z(1)\n";
Z z(1);
}
{
std::cout << "Z2 z(x);\n";
Z2 z(x);
}
{
std::cout << "Z2 z( (X()) )\n";
Z2 z( (X()) );
}
{
std::cout << "Z2 z(1)\n";
Z2 z(1);
}
}
Y2::Y2(X x): x_(x)
{
}
Z2::Z2(X const & x): x_(x)
{
}
Executive summary: the reference wins. It doesn't really matter. You knew
that already.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk