C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] std::array::size should be static
From: codusnocturnus (codusnocturnus_at_[hidden])
Date: 2020-06-13 00:53:20


Not sure what the use case is, but std::tuple_size can fill in for all 3 of those with std::array.

#include <array>
struct S {
std::array<int, 4> arr;

void foo() {
// arr.size() == arr.max_size()
// arr.size() != 0 -> !arr.empty()
static_assert(std::tuple_size<decltype(arr)>::value);
}
};

Sent with [ProtonMail](https://protonmail.com) Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, June 12, 2020 3:54 PM, Filippo Casarin via Std-Proposals <std-proposals_at_[hidden]> wrote:

> With the current c++20 standard the following code
>
> #include <array>
> struct S {
> std::array<int, 4> arr;
>
> void foo() {
> static_assert(arr.size());
> }
> };
>
> generate this error
>
> main.cpp: In member function ‘void S::foo()’:
> main.cpp:7:31: error: non-constant condition for static assertion
> 7 | static_assert(arr.size());
> | ~~~~~~~~^~
> main.cpp:7:31: error: use of ‘this’ in a constant expression
>
> This would work if std::array::size would be static, also I don't think any old code would break for this change.
>
> std::array::max_size and std::array::empty are similar and I think should be static.



STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups