Constexpr Library Additions: containers, v2

ISO/IEC JTC1 SC22 WG21 N3470 = 12-0160

2012-10-18

Benjamin Kosnik, bkoz@redhat.com

Daniel Krugler, daniel.kruegler@googlemail.com

Introduction

This paper details use of the ISO C++0x constexpr feature, as initially introduced in “Generalized Constant Expressions — Revision 5” (N2235) and incorporating all other subsequent changes as per ISO C++ draft N3376. This is the first revision of N3304, Constexpr Library Additions: containers. Several CWG issues have also influenced the language with respect to constexpr: see issues 1099, 1125, 1194, 1195, 1197, 1198, 1199 and c++-std-core postings number 17890 and 17912. Additional implementation experience, and subsequent changes to the core language have motivated the following changes and additions to the library specification.

Proposed Changes

A list of additional places in 23.3.2 Class template array that can exploit the constexpr language feature is below. For the changes listed, the new text is put in place in bold and green with the older text it is replacing struckthrough in red.

Proposed wording

a) Modify 23.3.2.1 [array.overview]  as follows:

reference

operator[](size_type n);

constexpr const_reference

operator[](size_type n) const;

reference

at(size_type n);

constexpr const_reference

at(size_type n) const;

reference

front();

constexpr const_reference

front() const;

reference

back();

constexpr const_reference

back() const;

b) Modify 23.3.2.9 [array.tuple]  as follows:

template <size_t I, class T, size_t N>

constexpr T& get(array<T, N>& a) noexcept;

template <size_t I, class T, size_t N>

constexpr T&& get(array<T, N>&& a) noexcept;

template <size_t I, class T, size_t N>

constexpr const T& get(const array<T, N>& a) noexcept;

Acknowledgments

Many thanks to Jason Merrill, Paolo Carlini, and Jonathan Wakely for reviewing this document and providing assistance.