Topic: Bug in CD2: assign(3)


Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1997/11/04
Raw View
Stefan Kuhlins wrote:
>
> Some container classes declare the member function
> assign as member template like this:
>
>   template <class T, class Allocator = allocator<T> >
>   class vector {
>   public:
>     template <class Size, class U>
>     void assign(Size n, const U& u = U());
>     // ...
>   };
>
> What should a compiler generate for a call like this?
>
>   vector<int> v;
>   v.assign(3);

Nothing. The type can't be deduced.

> What's the right way?

It's the standard conforming one:

void assign(Size n, const T& u);

That is, not template, no stupid default argument.

All these silly defaults have been droped, except
for string.

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ 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                             ]





Author: Stefan Kuhlins <kuhlins@wifo.uni-mannheim.de>
Date: 1997/11/04
Raw View
Some container classes declare the member function
assign as member template like this:

  template <class T, class Allocator = allocator<T> >
  class vector {
  public:
    template <class Size, class U>
    void assign(Size n, const U& u = U());
    // ...
  };

What should a compiler generate for a call like this?

  vector<int> v;
  v.assign(3);

It's not clear what type U should be!
Maybe this could work:

  v.template assign<int, int>(3);
  // see WP 14.2 (4) [temp.names]

A better solution might be:

  template <class Size, class U>
  void assign(Size n, const U& u = T());
                                   ^^^
I tested this with KCC, but it doesn't compile.

What's the right way?

- Stefan
---
[ 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                             ]