Topic: STL support for T (T&) (and a bug in the DWP)


Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/06/20
Raw View
I have designed a simple STL class and I wanted to support non const
copy ctors T (T&); I have tried to add annother construct template
but it didn't worked.

My question is, given:

    template <class T1, class T2>
    inline void construct(T1* p, T2& value);

    construct (pi, 5);

T1 is deduced as int, but my reading of the std imply that
deduction _can_ be done with T2 as int but the call isn't
a viable candidate.

(IMO the deduction can in general be done with T2 = const int
but my reading is that it isn't tried  14.8.2/4 [temp.deduct])

And there is only one candidate, the normal construct:

    template <class T1, class T2>
    inline void construct(T1* p, const T2& value);

so to add it shouldn't cause problems.

Can anyone comment if it is correct ? (In practice I get
ambiguity or warning about non-const ref.)

BTW, when I was looking for the answer of the question, I have
found:

14.8.2 Template argument deduction [temp.deduct]:

> 17If function template-arguments are explicitly  specified  in  a  call,
>   they  shall  be  specified in declaration order of their corresponding
>   template-parameters.  Trailing arguments can be left out of a list  of
>   explicit template-arguments.  [Example:
>   template<class X, class Y, class Z> X f(Y,Z);
>           void g()
>           {
>                   f<int,char*,double>("aa",3.0);
>                   f<int,char*>("aa",3.0); // Z is deduced to be double
>                   f<int>("aa",3.0);       // Y is deduced to be char*, and
>                                           // Z is deduced to be double
>                   f("aa",3.0);            // error: X cannot be deduced
>           }
>    --end example]

I think this should be const char*.

--

Valentin Bonnard
mailto:bonnardv@pratique.fr
http://www.pratique.fr/~bonnardv (Informations sur le C++ en Francais)
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]