C++ Logo

std-proposals

Advanced search

Re: std::array::size should be static

From: connor horman <chorman64_at_[hidden]>
Date: Fri, 12 Jun 2020 19:21:09 -0400
Wouldn't this break generic stuff with collections that expect non-member
functions?

On Fri, Jun 12, 2020 at 18:56 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 mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-06-12 18:24:29