Topic: class template argument deduction


Author: ebeyeler_g@yahoo.com (Eric Beyeler)
Date: Mon, 5 Jan 2004 02:07:26 +0000 (UTC)
Raw View
Why is class template argument deduction not allowed (i.e. based on
constructor parameters?)

Eric Beyeler

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: tom_usenet@hotmail.com (tom_usenet)
Date: Mon, 5 Jan 2004 18:51:31 +0000 (UTC)
Raw View
On Mon, 5 Jan 2004 02:07:26 +0000 (UTC), ebeyeler_g@yahoo.com (Eric
Beyeler) wrote:

>Why is class template argument deduction not allowed (i.e. based on
>constructor parameters?)

I don't think its particularly easy to come up with good semantics
with regard to overloading - it is an unnecessary complication. The
new "auto" thing and "template typedefs" should help in many
situations:

auto t = f(); //f returns some complicated template type

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: pasa@lib.hu ("Balog Pal")
Date: Mon, 5 Jan 2004 23:42:32 +0000 (UTC)
Raw View
"tom_usenet" <tom_usenet@hotmail.com> wrote in message
news:14pivv8fobiaigcq4u3ski43a2khbtnl9k@4ax.com...

> I don't think its particularly easy to come up with good semantics
> with regard to overloading - it is an unnecessary complication. The
> new "auto" thing and "template typedefs" should help in many
> situations:
>
> auto t = f(); //f returns some complicated template type

Only we have to live long enough to see them working in copilers at hand...

Paul


---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: technews@kangaroologic.com ("Jonathan Turkanis")
Date: Tue, 6 Jan 2004 03:01:23 +0000 (UTC)
Raw View
"tom_usenet" <tom_usenet@hotmail.com> wrote in message
news:14pivv8fobiaigcq4u3ski43a2khbtnl9k@4ax.com...
> On Mon, 5 Jan 2004 02:07:26 +0000 (UTC), ebeyeler_g@yahoo.com (Eric
> Beyeler) wrote:
>
> >Why is class template argument deduction not allowed (i.e. based on
> >constructor parameters?)
>
> I don't think its particularly easy to come up with good semantics
> with regard to overloading - it is an unnecessary complication. The
> new "auto" thing and "template typedefs" should help in many
> situations:
>
> auto t = f(); //f returns some complicated template type
>

Also, in a high percentage of cases the deduction wouldn't succeed,
even when one might think it should. There are also cases in which the
decution would produce surprising results, esp. because of the
possibility of partial specializations which the programmer doesn't
know about.

I'll just give one example:

    template<typename T>
    struct mylist {
        // Construct a list of length 1.
        mylist(const T&);

        // Copy constructor.
        mylist(const mylist&);

        /* ... */
    };

    template<typename T>
    int size(const mylist<T>& list);

    int main()
    {
        mylist<int> list(5);
        // ...
        std::cout << "size = " << size(mylist(list)) << "\n";
    }

Does this print the size of a copy of list, or does it print the size
of a new mylist< mylist< int> >, or is it ambiguous? I think cases
like this would be very common.

Jonathan


---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]