Date: Sun, 14 Jun 2020 23:52:31 +0300
I also agree it must be static, however this will break code that calls
size via class pointer.
The static_assert can be done via template parameter too:
template<size_t N>
void f(std::array<int,N> const &){
static_assert(N);
}
On Sun, Jun 14, 2020 at 11:41 PM Michael Hava via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Technically yes – maybe even Container::max_size in general should be
> static.
>
>
>
> That’s an ABI break though and as there is a valid workaround (tuple_size)
> I’m not sure fixing this would have priority (let alone consensus) in LEWG…
>
>
>
> @Jake: not sure what you mean with "or have the ability to have static
> methods that provide a static interface and a non-static interface." as we
> already have that, arr.size() would still work if size was static…
>
>
>
> *From:* Std-Proposals <std-proposals-bounces_at_[hidden]> *On Behalf
> Of *Filippo Casarin via Std-Proposals
> *Sent:* Saturday, June 13, 2020 12:54 AM
> *To:* std-proposals_at_[hidden]
> *Cc:* Filippo Casarin <casarin.filippo17_at_[hidden]>
> *Subject:* [std-proposals] std::array::size should be static
>
>
>
> 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
>
size via class pointer.
The static_assert can be done via template parameter too:
template<size_t N>
void f(std::array<int,N> const &){
static_assert(N);
}
On Sun, Jun 14, 2020 at 11:41 PM Michael Hava via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> Technically yes – maybe even Container::max_size in general should be
> static.
>
>
>
> That’s an ABI break though and as there is a valid workaround (tuple_size)
> I’m not sure fixing this would have priority (let alone consensus) in LEWG…
>
>
>
> @Jake: not sure what you mean with "or have the ability to have static
> methods that provide a static interface and a non-static interface." as we
> already have that, arr.size() would still work if size was static…
>
>
>
> *From:* Std-Proposals <std-proposals-bounces_at_[hidden]> *On Behalf
> Of *Filippo Casarin via Std-Proposals
> *Sent:* Saturday, June 13, 2020 12:54 AM
> *To:* std-proposals_at_[hidden]
> *Cc:* Filippo Casarin <casarin.filippo17_at_[hidden]>
> *Subject:* [std-proposals] std::array::size should be static
>
>
>
> 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-14 15:56:17