From: Kris Prad on
The inserter function (from msdn):

template<class Container, class Iterator>
insert_iterator<Container> inserter(
Container& _Cont,
Iterator _It
);

It returns an object of insert_iterator.

Can't iterator type be obtained from Container type?

Something like:

template<class Container>
insert_iterator<Container> inserter(
Container& _Cont,
typename Container::iterator _It
);

In fact insert_iterator's ctor does this.

Kris

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Daniel Krügler on
On 16 Feb., 20:19, Kris Prad <krisp...(a)yahoo.co.uk> wrote:
> The inserter function (from msdn):
>
> template<class Container, class Iterator>
> insert_iterator<Container> inserter(
> Container& _Cont,
> Iterator _It
> );
>
> It returns an object of insert_iterator.

This is a perfect match against the C++03
standard.

> Can't iterator type be obtained from Container type?
>
> Something like:
>
> template<class Container>
> insert_iterator<Container> inserter(
> Container& _Cont,
> typename Container::iterator _It
> );

Sure, this is possible. And in retro-perspective
the current spec has been recognized as overly
generic, see

http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#561

> In fact insert_iterator's ctor does this.

Correct, and this is actually more evidence for
that defect.

HTH & Greetings from Bremen,

Daniel Kr�gler


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Pete Becker on
Pete Becker wrote:
> Kris Prad wrote:
>> The inserter function (from msdn):
>>
>> template<class Container, class Iterator>
>> insert_iterator<Container> inserter(
>> Container& _Cont,
>> Iterator _It
>> );
>>
>> It returns an object of insert_iterator.
>>
>> Can't iterator type be obtained from Container type?
>>
>
> Of course.
>
>> Something like:
>>
>> template<class Container>
>> insert_iterator<Container> inserter(
>> Container& _Cont,
>> typename Container::iterator _It
>> );
>>
>
> If that's all that was needed, that would indeed work. So there's a
> strong possibility that there's more going on here than that. To find
> out if that's the case, read the documentation. I'm sure that MSDN
> provides more than just the declaration...
>

Whoops, sorry: answered the wrong question. Yes, the type can be
obtained from the Container type, and, yes, your rewrite works just fine.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]