C++ Logo

std-proposals

Advanced search

[std-proposals] Only reason I don't use std::array

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 16 Aug 2023 20:07:06 +0100
I use source code management systems like Git and SVN, and so when I'm
making a code change, it's nice when the diff is minimal.

If I have a C-style array, I can do the following:

SomeType const arr[] = {
    something1,
    something2,
    something3,
};

Let's say my colleague adds a line between something1 and something2, while
simultaneously I add three lines between something3 and something4. There
won't be a clash when we try to push to the remote repository. But let's
say it was:

array<SomeType,3u> = {
    something1,
    something2,
    something3,
};

My colleague wants to change that first line to "array<SomeType,4u>", while
I want to change it to "array<SomeType,6u>".

And even if we don't have two or more people working on the same code base,
it's just plain convenient not to have to write the size of the array.

Can we devise a way of making the following possible:

array<SomeType> = {
    something1,
    something2,
    something3,
};

Perhaps something along the lines of:

template<typename T, std::size_t len>
class array {
    array(std::initializer_list<T> list -> len);
};

Received on 2023-08-16 19:07:08