Skip to content

Commit 89f09e3

Browse files
committed
Change array<T, 0>::begin() to return nullptr and make it constexpr.
1 parent 4332639 commit 89f09e3

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

include/boost/array.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,13 @@ namespace boost {
207207
typedef std::ptrdiff_t difference_type;
208208

209209
// iterator support
210-
iterator begin() BOOST_NOEXCEPT { return iterator( reinterpret_cast< T * >( this ) ); }
211-
const_iterator begin() const BOOST_NOEXCEPT { return const_iterator( reinterpret_cast< const T * >( this ) ); }
212-
const_iterator cbegin() const BOOST_NOEXCEPT { return const_iterator( reinterpret_cast< const T * >( this ) ); }
210+
BOOST_CXX14_CONSTEXPR iterator begin() BOOST_NOEXCEPT { return data(); }
211+
BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT { return data(); }
212+
BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT { return data(); }
213213

214-
iterator end() BOOST_NOEXCEPT { return begin(); }
215-
const_iterator end() const BOOST_NOEXCEPT { return begin(); }
216-
const_iterator cend() const BOOST_NOEXCEPT { return cbegin(); }
214+
BOOST_CXX14_CONSTEXPR iterator end() BOOST_NOEXCEPT { return begin(); }
215+
BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT { return begin(); }
216+
BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return cbegin(); }
217217

218218
// reverse iterator support
219219
typedef std::reverse_iterator<iterator> reverse_iterator;

test/array0.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ void RunTests()
4444
BOOST_TEST ( const_test_case.begin() == const_test_case.end());
4545
BOOST_TEST ( const_test_case.cbegin() == const_test_case.cend());
4646

47-
BOOST_TEST ( test_case.begin() != const_test_case.begin() );
47+
// BOOST_TEST ( test_case.begin() != const_test_case.begin() );
48+
//
49+
// TR1 specified that begin() must return a unique value for zero-sized
50+
// arrays. However, this makes constexpr unimplementable, and all standard
51+
// libraries have converged on using nullptr instead (see LWG issue 2157.)
52+
4853
if( test_case.data() == const_test_case.data() ) {
4954
// Value of data is unspecified in TR1, so no requirement this test pass or fail
5055
// However, it must compile!

0 commit comments

Comments
 (0)