This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This patch implements http://wg21.link/p0031 which adds constexpr to most operations on std::reverse_iterator, std::move_iterator, std::array, as well as std::advance, std::distance, and the range-access functions std::begin, std::rbegin etc. Strictly speaking, those functions should only be constexpr in C++17 and not before, but this patch makes them constexpr whenever possible. That means the changes are fully implemented for C++14 (and the feature-test macro is defined) but only partially implemented for C++11, because some of the functions can't be constexpr in C++11. My thinking is that if the committee has decided that these functions *should* be constexpr, and changed them for C++17, then it doesn't serve users to make them non-constexpr in C++11 and C++14 just because the standard says so. How do other people feel about that? The alternative would be to define a new _GLIBCXX17_CONSTEXPR macro and use it in all these places, so they're only constexpr in C++17 (and probably for -std=gnu++14 too, but not -std=c++14). How strict do we want to be about obeying the "implementors can't add constexpr" rule in these cases? Here's the patch, but I'm not committing it yet. * include/bits/range_access.h (begin, end, rbegin, rend, crbegin) (crend): Add constexpr specifier as per P0031R0. * include/bits/stl_iterator.h (reverse_iterator, move_iterator) (__make_reverse_iterator, make_reverse_iterator, make_move_iterator): Add _GLIBCXX_CONSTEXPR or _GLIBCXX14_CONSTEXPR as appropriate. * include/bits/stl_iterator_base_funcs.h (__distance, distance) (__advance, advance, next, prev): Likewise. * include/std/array (array::begin, array::end, array::rbegin) (array::rend, array::cbegin, array:cend, array::crbegin) (array::crend, array::operator[], array::at, array::front) (array::back, array::data): Likewise. * testsuite/24_iterators/headers/iterator/range_access.cc: Add constexpr. * testsuite/24_iterators/headers/iterator/synopsis.cc: Add constexpr to reverse_iterator operations, advance, and distance.
Attachment:
patch.txt
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |