Constexpr Library Additions: support/utilities
ISO/IEC JTC1 SC22 WG21 N3231 = 10-0221 - 2010-11-24
Benjamin Kosnik, bkoz@redhat.com
Addresses: LWG 2013
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 N3126. Several CWG issues also influence the language with respect to constexpr: see issues 1099, 1125, 1194, 1195, 1197, 1198, 1199 and c++-std-core postings number 17890 and 17912. For pair and tuple, see N3140. Additional implementation experience has motivated the following changes and additions to the library specification.
Proposed Changes
A list of additional places in Chapters 18 Support or 20 Utilities 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.
01. <initializer_list>
Add the following:
- Mark class template initializer_list’s default constructor and member functions
size, begin, and end constexpr.
- Mark function templates begin and end constexpr.
02. <utility>
Add the following:
- Mark pair copy and non-move constructors constexpr.
- Mark pair comparison operators ==, !=, >, >=, <, <= constexpr.
03. <tuple>
Add the following:
- Mark tuple copy and non-move constructor constexpr.
Proposed wording
a) Modify 18.9 as follows:
constexpr initializer_list();
constexpr size_t size() const;
constexpr const E* begin() const;
constexpr const E* end() const;
b) Modify 18.9.1 as follows:
constexpr initializer_list();
c) Modify 18.9.2 as follows:
constexpr const E* begin() const;
constexpr const E* end() const;
constexpr size_t size() const;
d) Modify 18.9.3 as follows:
template<class E> constexpr const E* begin(initializer_list<E> il);
e) Modify 20.3.5.2 as follows:
constexpr pair(const pair&) = default;
constexpr pair();
constexpr pair(const T1& x, const T2& y);
template<class U, class V> pair(U&& x, V&& y);
template<class U, class V> constexpr pair(const pair<U, V>& p);
f) Modify 20.3.5.3 as follows:
template <class T1, class T2>
constexpr bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y);
template <class T1, class T2>
constexpr bool operator<(const pair<T1, T2>& x, const pair<T1, T2>& y);
template <class T1, class T2>
constexpr bool operator!=(const pair<T1, T2>& x, const pair<T1, T2>& y);
template <class T1, class T2>
constexpr bool operator>(const pair<T1, T2>& x, const pair<T1, T2>& y);
template <class T1, class T2>
constexpr bool operator>=(const pair<T1, T2>& x, const pair<T1, T2>& y);
template <class T1, class T2>
constexpr bool operator<=(const pair<T1, T2>& x, const pair<T1, T2>& y);
g) Modify 20.4.2 as follows:
explicit constexpr tuple(const Types&...);
constexpr tuple(const tuple&) = default;
g) Modify 20.4.2.1 as follows:
explicit constexpr tuple(const Types&...);
constexpr tuple(const tuple&) = default;
Acknowledgments
Many thanks to Daniel Krügler, Alisdair Meredith, Jason Merrill, Paolo Carlini, and Jonathan Wakely for reviewing this document and providing assistance.