Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofResolved status.

2443.std::array member functions should beconstexpr

Section: 23.3.3[array]Status:ResolvedSubmitter: Peter SommerladOpened: 2014-10-06Last modified: 2020-09-06

Priority:Not Prioritized

View all otherissues in [array].

View all issues withResolved status.

Discussion:

When experimenting with C++14 relaxedconstexpr functions I made the observation that I couldn't usestd::array to create a table of data at compile time directly using loops in a function. However, a simple substitute I could use instead:

template <typename T, size_t n>struct ar {  T a[n];  constexpr ar() : a{{}}{}  constexpr auto data() const { return &a[0];}  constexpr T const & operator[](size_t i) const { return a[i]; }  constexpr T & operator[](size_t i) { return a[i]; }};template <size_t n>using arr = ar<size_t, n>; // std::array<size_t, n>;template <size_t n>constexpr auto make_tab(){  arr<n> result;  for(size_t i=0; i < n; ++i)    result[i] = (i+1)*(i+1); // cannot define operator[] for mutable array...  return result;}template <size_t n>constexpr auto squares=make_tab< n>();int main() {  int dummy[squares<5>[3]];}

Therefore, I suggest that all member functions ofstd::array should be madeconstexpr to make the type usable inconstexpr functions.

Wording should be straight forward, may be with the exception offill, which would requirefill_n to beconstexpr as well.

[2014-11 Urbana]

Move to LEWG

The extent to whichconstexpr becomes a part of the Library design is a policymatter best handled initially by LEWG.

[08-2016, Post-Chicago]

Move to Tentatively Resolved

Proposed resolution:

This functionality is provided byP0031R0


[8]ページ先頭

©2009-2025 Movatter.jp