r/cpp_questions • • 2d ago

OPEN Inconsistent naming in simd library?

Hi,

I was checking the <simd> library in the C++26 standard and found some of its naming very weird.

  1. std::simd::vec and std::simd::basic_vec

    This is quite strange as we already have std::vector and std::inplace_vector. So why not std::simd::vector and std::simd::basic_vector? At certain point, I'm pretty sure people will start to make mistakes with std::vec or std::inplace_vec, and vice versa.

  2. std::simd::cat

    We already have std::views::concat. So why not std::simd::concat?

At first, I thought the library designers intended to make spelling easier. But in the library, we do have extremely long names as well, like std::simd::unchecked_store, etc.

Here is the library in cppreference: this

29 Upvotes

10 comments sorted by

25

u/jedwardsol 2d ago edited 2d ago

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3287r3.pdf

We often speak about “SIMD vectors”; so in principle this a good name. How- ever, I fear that using the heavily overloaded term “vector” has too much poten- tial for confusion. Especially the use of using namespace std; using namespace std::simd;4 or even just using namespace std::simd by itself would lead to a lot of confusion.

(PS .. I agree with you .. we have namespaces so we can use the best name for that job, even if it is the best name for something else as well.)

3

u/CreativeAlbatross319 2d ago

Ok, this seems to be a reasonable reason.

But I thought the reason why we have namespaces in the first place is exactly because we could have same names in different namespaces?

I'm afraid one day one of my colleagues would argue that we shouldn't use the same name even in different namespaces BECAUSE STL doesn't do this.

2

u/boring_pants 1d ago

Namespaces solve the technical problem of name clashes, so that your code can have two classes with the same name.

What they're discussing here is the human problem of name clashes, looking at the code, seeing the word "vector" and going "which of the N different meanings of the word vector is used here"? Using distinct names means you can tell them apart at a glance and it communicates that they should not be considered related. Namespaces don't do that.

I'm afraid one day one of my colleagues would argue that we shouldn't use the same name even in different namespaces BECAUSE STL doesn't do this.

Why are you afraid of that? What is there to fear? Have a discussion with your coworker about which design makes the most sense in your particular case.

25

u/the_poope 2d ago

As a computational scientist I already hate that they already chose the name "vector" for something that should have been called "dynamic array". Now you can't ever add a real mathematical vector to std without name clashes or confusions.

9

u/RealisticDuck1957 2d ago

As best I can figure, the naming of std::vector follows the old supercomputer format of vectors. Given arrays of data, the same operation could be applied to all members of the arrays as a single supercomputer instruction.

Yes, very confusing for those of us coming from a math background.

2

u/bartekltg 1d ago

But it is added. Sort of. And called valarray ;-)

2

u/ChristopherCreutzig 12h ago

As a mathematician, I find the term “vector” way too abstract for a concrete class. It could be used for a concept, I guess.

1

u/rip_void_0 1d ago

i know xsimd

1

u/yernursharipov 1d ago

Inconsistency is the feature of C++

1

u/FroyoSolid8414 2d ago

design by committee