Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8580021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:44:15+00:00 2026-06-11T20:44:15+00:00

Yes, this has been asked before , and the answer has been: valarray s

  • 0

Yes, this has been asked before, and the answer has been:

valarrays (value arrays) are intended to bring some of the speed of Fortran to C++. You wouldn’t make a valarray of pointers so the compiler can make assumptions about the code and optimise it better. (The main reason that Fortran is so fast is that there is no pointer type so there can be no pointer aliasing.)

or:

valarray is also supposed to eliminate any possibility of aliasing […]

But these answers make no sense to me.

valarray and vector are class templates, and as such, they don’t even exist until instantiated.
And of course, a vector<int> doesn’t cause aliasing issues any more than valarray<int> does.

Given this, what was the purpose of valarray, and why did they not simply put the same functionality into vector instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:44:16+00:00Added an answer on June 11, 2026 at 8:44 pm

    Separation of concern? A vector and a valarray solve different problems. Quoting from the standard, a vector is a (§23.3.6.1 [vector.overview] p1)

    … sequence container that supports random access iterators. In addition, it supports (amortized) constant time insert and erase operations at the end; insert and erase in the middle take linear time. Storage management is handled automatically, though hints can be given to improve efficiency.

    while a valarray is a (§26.6.2.1 [template.valarray.overview] p1)

    … one-dimensional smart array, with elements numbered sequentially from zero. It is a representation of the mathematical concept of an ordered set of values. The illusion of higher dimensionality may be produced by the familiar idiom of computed indices, together with the powerful subsetting capabilities provided by the generalized subscript operators.

    As you can see, they serve different purposes. A vector is a generalized dynamic array, while a valarray represents a set of values. It’s also not resizeable and only assignable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I know this question has been asked before, but I can't find an
Yes, I know this question has been asked dozens of times before. However, when
Yes, this question has been asked before, but I don't feel there's been a
I know this has been asked before but I have looked at every answer
Yes, I know this question has been asked 1000 times before... here is the
Yes, I know this question has been asked a lot of times, but I
I know this question has been asked before and I read all the answers
I know this has probably been asked before, but I can't find it with
I know this has been asked many times, but I cant find answer to
Apologies if this has been asked already, I can't find the answer in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.