C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using valarray

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Busin
Guest





PostPosted: Tue Jun 29, 2004 7:29 am    Post subject: Using valarray Reply with quote



valarray<bool> va1(10);

// Initialize va1 here?

valarray<bool> va2 (80);

va2 = va1;

Do we have to initialize va1 like using for loop above (since if not, the
printout of va1 will display garbage)?

Can va1 be initialized like "valarray<bool> va1(10, false);" when defining
it?

Is it ok to assign va1 to va2? Does va2 have to be specified with a size
before assigning va1 to it? Must the size of va2 be larger than va1?

Thanks!



Back to top
John Harrison
Guest





PostPosted: Tue Jun 29, 2004 8:19 am    Post subject: Re: Using valarray Reply with quote




"Busin" <businm (AT) fidrep (DOT) com> wrote

Quote:
valarray<bool> va1(10);

// Initialize va1 here?

valarray<bool> va2 (80);

va2 = va1;

Do we have to initialize va1 like using for loop above (since if not, the
printout of va1 will display garbage)?

No, the elements of va1 will be default constructed. I believe for a bool
this should mean it will be set to false. Your compiler may not implement
this correctly though.

Quote:

Can va1 be initialized like "valarray<bool> va1(10, false);" when defining
it?

No, like this

valarray<bool> val(false, 10);

Quote:

Is it ok to assign va1 to va2?

Yes

Quote:
Does va2 have to be specified with a size
before assigning va1 to it?

No

Quote:
Must the size of va2 be larger than va1?

No, va2 will change its size to be the same as va1

john



Back to top
tom_usenet
Guest





PostPosted: Tue Jun 29, 2004 8:54 am    Post subject: Re: Using valarray Reply with quote



On Tue, 29 Jun 2004 09:19:49 +0100, "John Harrison"
<john_andronicus (AT) hotmail (DOT) com> wrote:

Quote:

"Busin" <businm (AT) fidrep (DOT) com> wrote in message
news:8T8Ec.158035$Gx4.68371 (AT) bgtnsc04-news (DOT) ops.worldnet.att.net...
valarray<bool> va1(10);

// Initialize va1 here?

valarray<bool> va2 (80);

va2 = va1;

Is it ok to assign va1 to va2?

Yes

No, it's undefined behaviour, since the lengths don't match.

Quote:
Does va2 have to be specified with a size
before assigning va1 to it?

No

Yes.

Quote:
Must the size of va2 be larger than va1?

No, va2 will change its size to be the same as va1

The sizes of va2 and va1 must be exactly the same. See 26.3.2.2.

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

Back to top
John Harrison
Guest





PostPosted: Tue Jun 29, 2004 11:04 am    Post subject: Re: Using valarray Reply with quote


"tom_usenet" <tom_usenet (AT) hotmail (DOT) com> wrote

Quote:
On Tue, 29 Jun 2004 09:19:49 +0100, "John Harrison"
[email]john_andronicus (AT) hotmail (DOT) com[/email]> wrote:


"Busin" <businm (AT) fidrep (DOT) com> wrote in message
news:8T8Ec.158035$Gx4.68371 (AT) bgtnsc04-news (DOT) ops.worldnet.att.net...
valarray<bool> va1(10);

// Initialize va1 here?

valarray<bool> va2 (80);

va2 = va1;

Is it ok to assign va1 to va2?

Yes

No, it's undefined behaviour, since the lengths don't match.

Does va2 have to be specified with a size
before assigning va1 to it?

No

Yes.

Must the size of va2 be larger than va1?

No, va2 will change its size to be the same as va1

The sizes of va2 and va1 must be exactly the same. See 26.3.2.2.


OK, must have been getting confused with vector. Apologies.

john



Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.