C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] std::array::size should be static
From: connor horman (chorman64_at_[hidden])
Date: 2020-06-12 18:21:09


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
>



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

Standard Proposals Archives on Google Groups