C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] std::array::size should be static
From: Filippo Casarin (casarin.filippo17_at_[hidden])
Date: 2020-06-12 17:54:10


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