C++ Logo

std-proposals

Advanced search

std::array::size should be static

From: Filippo Casarin <casarin.filippo17_at_[hidden]>
Date: Sat, 13 Jun 2020 00:54:10 +0200
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.

Received on 2020-06-12 17:59:00