473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using valarray

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!

Jul 22 '05 #1
3 4657

"Busin" <bu****@fidrep.com> wrote in message
news:8T********************@bgtnsc04-news.ops.worldnet.att.net...
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.

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

valarray<bool> val(false, 10);

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


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

john
Jul 22 '05 #2
On Tue, 29 Jun 2004 09:19:49 +0100, "John Harrison"
<jo*************@hotmail.com> wrote:

"Busin" <bu****@fidrep.com> wrote in message
news:8T********************@bgtnsc04-news.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.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3

"tom_usenet" <to********@hotmail.com> wrote in message
news:7f********************************@4ax.com...
On Tue, 29 Jun 2004 09:19:49 +0100, "John Harrison"
<jo*************@hotmail.com> wrote:

"Busin" <bu****@fidrep.com> wrote in message
news:8T********************@bgtnsc04-news.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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christian Brechbühler | last post by:
The template std::valarray behaves pretty much like a mathematical vector. Arithmetic operators apply elementwise. Now I'd like to extend this to a user-defined type, e.g., complex. ...
2
by: Jim West | last post by:
The GNU implementation of the valarray header (g++ version 3.3.2) includes the comment: // This complication is so to make valarray<valarray<T> > work // even though it is not required by the...
3
by: Peter | last post by:
Hi everybody, I am unfortunately stuck with a probably very simple problem. I made a class called Particle with a valarray (STL) as a class member. The code for the class goes like this: ...
1
by: ES Kim | last post by:
comp.std.c++ would be a better place for this question. Forgive me, but I can't post anything on moderated newsgroups for some reason. valarray doesn't have iterators of its own, which makes...
1
by: ES Kim | last post by:
Here's a code fragment from TC++PL, p679: void f(valarray<double>& v) { size_t i = { 3, 2, 1, 0 }; valarray<size_t> index(i, 4); valarray<double> vv = log(v); } Every compiler I tried...
1
by: Oliver Block | last post by:
I have a (9x9) valarray std::valarray<int> va(81); va = 0; // fil all elements with zeros I am taking row slices like that: std::slice_array<int> slr = va; // r = row; a value between 1...
2
by: Jan Callewaert | last post by:
Hi, since I want to specify an extra function for a std::valarray<float>, I want to subclass it: class FVector : public std::valarray<float> { public: FVector() : std::valarray<float>() {}...
3
by: klucar | last post by:
I'll start off differently by showing what I know how to do: valarray<float> va(100, 0.0f); float* fp; fp = &va; some_c_function( fp, va.size() ); What I want to do though is quite the...
5
by: Chris Forone | last post by:
Hello group, g++ (3.4.2, mingw): float init = {1.f, 2.f, 3.f}; std::map<std::string, std::valarray<float mp; mp = std::valarray(init, 3); mp.size(); // should be 3, but IS 0!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.