Hi,

The first assignment statement doesn't work because I didn't use []s
or *s. Is this no longer acceptable syntax or is it a VC++ idiom?

thanks,

quakerP


char cReadBuf[] = "1234567";
deque<char> cDdeq1(8);

void main(void)
{
int i;
// This does not work.
cDdeq1.assign(cReadBuf, cReadBuf+8);

// This works.
cDdeq1.assign(cReadBuf[0], cReadBuf[8]+8);

//This works too.
cDdeq1.assign(*cReadBuf, *cReadBuf+8);

for(i = 0; i < 8; i++)
cout << cReadBuf[i] << endl;

}

Re: deque assign syntax by Igor

Igor
Fri Feb 23 11:31:37 CST 2007

goodTweetieBird@hotmail.com wrote:
> char cReadBuf[] = "1234567";
> deque<char> cDdeq1(8);
>
> void main(void)
> {
> int i;
> // This does not work.
> cDdeq1.assign(cReadBuf, cReadBuf+8);

Works for me. Are you using VC6, by any chance?

> // This works.
> cDdeq1.assign(cReadBuf[0], cReadBuf[8]+8);

While it compiles, it doesn't do what you seem to think it does. It uses
an overload of assign() that takes number of elements as the first
parameter, and an element as the second. The result of this assignment
would be a deque containing character X repeated N times. Here X is the
character whose code is Y+8, where Y is some garbage byte located beyond
cReadBuf array. N is 49 (which happens to be an ASCII code of character
'1')

> //This works too.
> cDdeq1.assign(*cReadBuf, *cReadBuf+8);

This "works" similarly to the case above.

> for(i = 0; i < 8; i++)
> cout << cReadBuf[i] << endl;
> }

Any reason you are printing contents of cReadBuf array, and not contents
of the deque? Had you done the latter, the problem with two statements
you declared "working" would become obvious.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: deque assign syntax by goodTweetieBird

goodTweetieBird
Fri Feb 23 12:24:30 CST 2007

On Feb 23, 11:31 am, "Igor Tandetnik" <itandet...@mvps.org> wrote:
> goodTweetieB...@hotmail.com wrote:
> > char cReadBuf[] = "1234567";
> > deque<char> cDdeq1(8);
>
> > void main(void)
> > {
> > int i;
> > // This does not work.
> > cDdeq1.assign(cReadBuf, cReadBuf+8);
>
> Works for me. Are you using VC6, by any chance?
>
> > // This works.
> > cDdeq1.assign(cReadBuf[0], cReadBuf[8]+8);
>
> While it compiles, it doesn't do what you seem to think it does. It uses
> an overload of assign() that takes number of elements as the first
> parameter, and an element as the second. The result of this assignment
> would be a deque containing character X repeated N times. Here X is the
> character whose code is Y+8, where Y is some garbage byte located beyond
> cReadBuf array. N is 49 (which happens to be an ASCII code of character
> '1')
>
> > //This works too.
> > cDdeq1.assign(*cReadBuf, *cReadBuf+8);
>
> This "works" similarly to the case above.
>
> > for(i = 0; i < 8; i++)
> > cout << cReadBuf[i] << endl;
> > }
>
> Any reason you are printing contents of cReadBuf array, and not contents
> of the deque? Had you done the latter, the problem with two statements
> you declared "working" would become obvious.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925

Oops, should have cleaned it up b4 posting. The print is an artifact
of some back and forth debugging.

Yes, I am using VC6.

thanks


Re: deque assign syntax by Victor

Victor
Fri Feb 23 12:38:38 CST 2007

goodTweetieBird@hotmail.com wrote:
> On Feb 23, 11:31 am, "Igor Tandetnik" <itandet...@mvps.org> wrote:
>> goodTweetieB...@hotmail.com wrote:
>>> char cReadBuf[] = "1234567";
>>> deque<char> cDdeq1(8);
>>
>>> void main(void)
>>> {
>>> int i;
>>> // This does not work.
>>> cDdeq1.assign(cReadBuf, cReadBuf+8);
>>
>> Works for me. Are you using VC6, by any chance?
>>
[..]
>
> Yes, I am using VC6.

In that case you're SOL. VC6 does not support member templates,
which means std::deque does not have 'assign' as a template, which
means you need to use 'std::copy'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask



Re: deque assign syntax by goodTweetieBird

goodTweetieBird
Fri Feb 23 12:52:41 CST 2007

On Feb 23, 12:38 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> goodTweetieB...@hotmail.com wrote:
> > On Feb 23, 11:31 am, "Igor Tandetnik" <itandet...@mvps.org> wrote:
> >> goodTweetieB...@hotmail.com wrote:
> >>> char cReadBuf[] = "1234567";
> >>> deque<char> cDdeq1(8);
>
> >>> void main(void)
> >>> {
> >>> int i;
> >>> // This does not work.
> >>> cDdeq1.assign(cReadBuf, cReadBuf+8);
>
> >> Works for me. Are you using VC6, by any chance?
>
> [..]
>
> > Yes, I am using VC6.
>
> In that case you're SOL. VC6 does not support member templates,
> which means std::deque does not have 'assign' as a template, which
> means you need to use 'std::copy'.
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask

Thanks, I will try that again. How do I specify array begin and end
points to InputIterator _First and InputIterator _Last in VC6?


Re: deque assign syntax by Igor

Igor
Fri Feb 23 13:06:09 CST 2007

goodTweetieBird@hotmail.com wrote:
> Thanks, I will try that again. How do I specify array begin and end
> points to InputIterator _First and InputIterator _Last in VC6?

You had it right in the first attempt at deque.assign call:

copy(cReadBuf, cReadBuf+8, back_inserter(cDdeq1));

Except that you should consider whether you really want cReadBuf+8 and
not cReadBuf+7. Do you want 0 as the last element of the decque? It
makes sense in an array of char, but not so much in an STL container.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: deque assign syntax by goodTweetieBird

goodTweetieBird
Fri Feb 23 13:34:48 CST 2007

On Feb 23, 1:06 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:
> goodTweetieB...@hotmail.com wrote:
> > Thanks, I will try that again. How do I specify array begin and end
> > points to InputIterator _First and InputIterator _Last in VC6?
>
> You had it right in the first attempt at deque.assign call:
>
> copy(cReadBuf, cReadBuf+8, back_inserter(cDdeq1));
>

That works, was not familiar with back_inserter, was trying to
use .end().

> Except that you should consider whether you really want cReadBuf+8 and
> not cReadBuf+7. Do you want 0 as the last element of the decque? It
> makes sense in an array of char, but not so much in an STL container.
> --

It came from my discussion with Victor "Moving data from array to
deque" earlier today.
http://groups.google.com/group/microsoft.public.vc.language/browse_thread/thread/22da4358c739ce65/59d16dbf81a5e35a?hl=en#59d16dbf81a5e35a
In some container operations I have seen the last element referred to
this way.

You both have helped a lot.


Thank you again....