Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2000-08-19 14:12:11


David Abrahams wrote on 8/19/2000 1:38 PM
>> Yes, but I don't think that really applies in this case. There really is no
>> excuse for modifying an argument to output formatting, is there?

Karl Nelson wrote on 8/19/2000 2:46 PM
>It does actually, because otherwise you are forcing all types to have
>a T(const T&). Many classes this may be expensive or perhaps not
>the intended meaning. Thus by forcing copy by value you have no options.
<snip>
><dreamland>
>If C++ wanted to deal with this problem they would allow specifications
>in the template type. Thus rather then having to define
>
> template <class T1, class T2, class T3>
> void foo(T1& t1,T2& t2,T3& t2) {bar(t1,t2,t3);}
> template <class T1, class T2, class T3>
> void foo(const T1& t1,T2& t2,T3& t2) {bar(t1,t2,t3);}
> template <class T1, class T2, class T3>
> void foo(T1& t1,const T2& t2,T3& t2) {bar(t1,t2,t3);}
> template <class T1, class T2, class T3>
> void foo(T1& t1,T2& t2,const T3& t2) {bar(t1,t2,t3);}
> ...
>
>when I just want to proxy arguments through, I could could
>define something like...
>
> template <class &T1, class &T2, class &T3>
> void foo(T1 t1,T2 t2,T3 t2) {bar(t1,t2,t3);}
>
>which would load all combinations of reference types.
>
>But honestly unless I suddenly because all power C++ lord and
>master and could magically control committee members with my
>mind it isn't going to happen. :-)
></dreamland>

I'm probably missing something very silly, but this sub-thread has me
totally confused. I'm not seeing the answer to Dave's question of having
an overloaded function with one version modifying its argument (via T&)
and another not (uses const T&). The response appears to be: to allow
processing of objects that are not copyable. But I've probably skimmed a
little too quickly and gotten sentences out of context. That can't be
right:

struct A
{
        A() {}
private:
        A(const A&);
};

template <class T>
void
foo(const T&)
{
}

int main()
{
        foo(A());
}

Could you clarify Karl?

Thanks,
-Howard


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