diff --git a/include/array b/include/array index d3f8463cf..7e205cbf8 100644 --- a/include/array +++ b/include/array @@ -149,31 +149,31 @@ struct _LIBCPP_TYPE_VIS_ONLY array { _VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);} // iterators: - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 iterator begin() _NOEXCEPT {return iterator(__elems_);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator cbegin() const _NOEXCEPT {return begin();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_iterator cend() const _NOEXCEPT {return end();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const_reverse_iterator crend() const _NOEXCEPT {return rend();} // capacity: @@ -195,9 +195,9 @@ struct _LIBCPP_TYPE_VIS_ONLY array _LIBCPP_INLINE_VISIBILITY reference back() {return __elems_[_Size > 0 ? _Size-1 : 0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 value_type* data() _NOEXCEPT {return __elems_;} - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 const value_type* data() const _NOEXCEPT {return __elems_;} }; diff --git a/include/iterator b/include/iterator index ba9a83b9e..797ec5332 100644 --- a/include/iterator +++ b/include/iterator @@ -378,25 +378,25 @@ public: bool failed() const noexcept; }; -template auto begin(C& c) -> decltype(c.begin()); -template auto begin(const C& c) -> decltype(c.begin()); -template auto end(C& c) -> decltype(c.end()); -template auto end(const C& c) -> decltype(c.end()); -template T* begin(T (&array)[N]); -template T* end(T (&array)[N]); +template constexpr auto begin(C& c) -> decltype(c.begin()); +template constexpr auto begin(const C& c) -> decltype(c.begin()); +template constexpr auto end(C& c) -> decltype(c.end()); +template constexpr auto end(const C& c) -> decltype(c.end()); +template constexpr T* begin(T (&array)[N]); +template constexpr T* end(T (&array)[N]); -template auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14 -template auto cend(const C& c) -> decltype(std::end(c)); // C++14 -template auto rbegin(C& c) -> decltype(c.rbegin()); // C++14 -template auto rbegin(const C& c) -> decltype(c.rbegin()); // C++14 -template auto rend(C& c) -> decltype(c.rend()); // C++14 -template auto rend(const C& c) -> decltype(c.rend()); // C++14 -template reverse_iterator rbegin(initializer_list il); // C++14 -template reverse_iterator rend(initializer_list il); // C++14 -template reverse_iterator rbegin(T (&array)[N]); // C++14 -template reverse_iterator rend(T (&array)[N]); // C++14 -template auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 -template auto crend(const C& c) -> decltype(std::rend(c)); // C++14 +template auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 +template auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 +template auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 +template auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 +template auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 +template constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 +template reverse_iterator constexpr rbegin(initializer_list il); // C++14 +template reverse_iterator constexpr rend(initializer_list il); // C++14 +template reverse_iterator constexpr rbegin(T (&array)[N]); // C++14 +template reverse_iterator constexpr rend(T (&array)[N]); // C++14 +template constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 +template constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 // 24.8, container access: template constexpr auto size(const C& c) -> decltype(c.size()); // C++17 @@ -1616,7 +1616,7 @@ end(_Tp (&__array)[_Np]) #if !defined(_LIBCPP_CXX03_LANG) template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(_Cp& __c) -> decltype(__c.begin()) { @@ -1624,7 +1624,7 @@ begin(_Cp& __c) -> decltype(__c.begin()) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(const _Cp& __c) -> decltype(__c.begin()) { @@ -1632,7 +1632,7 @@ begin(const _Cp& __c) -> decltype(__c.begin()) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(_Cp& __c) -> decltype(__c.end()) { @@ -1640,7 +1640,7 @@ end(_Cp& __c) -> decltype(__c.end()) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(const _Cp& __c) -> decltype(__c.end()) { @@ -1650,28 +1650,28 @@ end(const _Cp& __c) -> decltype(__c.end()) #if _LIBCPP_STD_VER > 11 template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array + _Np); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rbegin(initializer_list<_Ep> __il) { return reverse_iterator(__il.end()); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rend(initializer_list<_Ep> __il) { return reverse_iterator(__il.begin()); @@ -1692,42 +1692,42 @@ auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(_Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(const _Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) { return _VSTD::rbegin(__c); } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) { return _VSTD::rend(__c); diff --git a/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/test/std/containers/sequences/array/array.data/data_const.pass.cpp index 58840e940..5be082eeb 100644 --- a/test/std/containers/sequences/array/array.data/data_const.pass.cpp +++ b/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -14,6 +14,8 @@ #include #include +#include "test_macros.h" + // std::array is explicitly allowed to be initialized with A a = { init-list };. // Disable the missing braces warning for this reason. #include "disable_missing_braces_warning.h" @@ -36,4 +38,16 @@ int main() const T* p = c.data(); (void)p; // to placate scan-build } +#if TEST_STD_VER > 14 + { + typedef std::array C; + constexpr C c1{0,1,2,3,4}; + constexpr const C c2{0,1,2,3,4}; + + static_assert ( c1.data() == &c1[0], ""); + static_assert ( *c1.data() == c1[0], ""); + static_assert ( c2.data() == &c2[0], ""); + static_assert ( *c2.data() == c2[0], ""); + } +#endif } diff --git a/test/std/containers/sequences/array/iterators.pass.cpp b/test/std/containers/sequences/array/iterators.pass.cpp index 1f9904e1f..7d9050800 100644 --- a/test/std/containers/sequences/array/iterators.pass.cpp +++ b/test/std/containers/sequences/array/iterators.pass.cpp @@ -17,6 +17,10 @@ #include "test_macros.h" +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + int main() { { @@ -109,4 +113,33 @@ int main() } } #endif +#if TEST_STD_VER > 14 + { + typedef std::array C; + constexpr C c{0,1,2,3,4}; + + static_assert ( c.begin() == std::begin(c), ""); + static_assert ( c.cbegin() == std::cbegin(c), ""); + static_assert ( c.end() == std::end(c), ""); + static_assert ( c.cend() == std::cend(c), ""); + + static_assert ( c.rbegin() == std::rbegin(c), ""); + static_assert ( c.crbegin() == std::crbegin(c), ""); + static_assert ( c.rend() == std::rend(c), ""); + static_assert ( c.crend() == std::crend(c), ""); + + static_assert ( std::begin(c) != std::end(c), ""); + static_assert ( std::rbegin(c) != std::rend(c), ""); + static_assert ( std::cbegin(c) != std::cend(c), ""); + static_assert ( std::crbegin(c) != std::crend(c), ""); + + static_assert ( *c.begin() == 0, ""); + static_assert ( *c.rbegin() == 4, ""); + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } +#endif } diff --git a/test/std/iterators/iterator.range/begin-end.pass.cpp b/test/std/iterators/iterator.range/begin-end.pass.cpp index 681869191..a0774888d 100644 --- a/test/std/iterators/iterator.range/begin-end.pass.cpp +++ b/test/std/iterators/iterator.range/begin-end.pass.cpp @@ -10,12 +10,25 @@ // XFAIL: c++03, c++98 // -// template auto begin(C& c) -> decltype(c.begin()); -// template auto begin(const C& c) -> decltype(c.begin()); -// template auto end(C& c) -> decltype(c.end()); -// template auto end(const C& c) -> decltype(c.end()); -// template reverse_iterator rbegin(initializer_list il); -// template reverse_iterator rend(initializer_list il); +// template constexpr auto begin(C& c) -> decltype(c.begin()); +// template constexpr auto begin(const C& c) -> decltype(c.begin()); +// template constexpr auto cbegin(const C& c) -> decltype(std::begin(c)); // C++14 +// template constexpr auto cend(const C& c) -> decltype(std::end(c)); // C++14 +// template constexpr auto end (C& c) -> decltype(c.end()); +// template constexpr auto end (const C& c) -> decltype(c.end()); +// template constexpr reverse_iterator rbegin(initializer_list il); +// template constexpr reverse_iterator rend (initializer_list il); +// +// template auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 +// template auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 +// template auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 +// template constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 +// template reverse_iterator constexpr rbegin(T (&array)[N]); // C++14 +// template reverse_iterator constexpr rend(T (&array)[N]); // C++14 +// template constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 +// template constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 +// +// All of these are constexpr in C++17 #include "test_macros.h" @@ -26,6 +39,10 @@ #include #include +// std::array is explicitly allowed to be initialized with A a = { init-list };. +// Disable the missing braces warning for this reason. +#include "disable_missing_braces_warning.h" + template void test_const_container( const C & c, typename C::value_type val ) { assert ( std::begin(c) == c.begin()); @@ -142,4 +159,43 @@ int main(){ constexpr const int *e = std::cend(arrA); static_assert(e - b == 3, ""); #endif + +#if TEST_STD_VER > 14 + { + typedef std::array C; + constexpr const C c{0,1,2,3,4}; + + static_assert ( c.begin() == std::begin(c), ""); + static_assert ( c.cbegin() == std::cbegin(c), ""); + static_assert ( c.end() == std::end(c), ""); + static_assert ( c.cend() == std::cend(c), ""); + + static_assert ( c.rbegin() == std::rbegin(c), ""); + static_assert ( c.crbegin() == std::crbegin(c), ""); + static_assert ( c.rend() == std::rend(c), ""); + static_assert ( c.crend() == std::crend(c), ""); + + static_assert ( std::begin(c) != std::end(c), ""); + static_assert ( std::rbegin(c) != std::rend(c), ""); + static_assert ( std::cbegin(c) != std::cend(c), ""); + static_assert ( std::crbegin(c) != std::crend(c), ""); + + static_assert ( *c.begin() == 0, ""); + static_assert ( *c.rbegin() == 4, ""); + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } + + { + static constexpr const int c[] = {0,1,2,3,4}; + + static_assert ( *std::begin(c) == 0, "" ); + static_assert ( *std::cbegin(c) == 0, "" ); + static_assert ( *std::rbegin(c) == 4, "" ); + static_assert ( *std::crbegin(c) == 4, "" ); + } +#endif } diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 824d09ce5..e90f4b4df 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -90,7 +90,7 @@ P0025R0LWGAn algorithm to "clamp" a value between a pair of boundary valuesJacksonvilleComplete3.9 P0154R1LWGconstexpr std::hardware_{constructive,destructive}_interference_sizeJacksonville P0030R1LWGProposal to Introduce a 3-Argument Overload to std::hypotJacksonvilleComplete3.9 - P0031R0LWGA Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range AccessJacksonvilleIn progress4.0 + P0031R0LWGA Proposal to Add Constexpr Modifiers to reverse_iterator, move_iterator, array and Range AccessJacksonvilleComplete4.0 P0272R1LWGGive std::string a non-const .data() member functionJacksonvilleComplete3.9 P0077R2LWGis_callable, the missing INVOKE related traitJacksonvilleComplete3.9 @@ -417,7 +417,7 @@ -

Last Updated: 3-Jan-2017

+

Last Updated: 4-Jan-2017