Skip to content

Commit

Permalink
Change array<T, 0>::begin() to return nullptr and make it constexpr.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jan 26, 2025
1 parent 4332639 commit 89f09e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions include/boost/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ namespace boost {
typedef std::ptrdiff_t difference_type;

// iterator support
iterator begin() BOOST_NOEXCEPT { return iterator( reinterpret_cast< T * >( this ) ); }
const_iterator begin() const BOOST_NOEXCEPT { return const_iterator( reinterpret_cast< const T * >( this ) ); }
const_iterator cbegin() const BOOST_NOEXCEPT { return const_iterator( reinterpret_cast< const T * >( this ) ); }
BOOST_CXX14_CONSTEXPR iterator begin() BOOST_NOEXCEPT { return data(); }
BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT { return data(); }
BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT { return data(); }

iterator end() BOOST_NOEXCEPT { return begin(); }
const_iterator end() const BOOST_NOEXCEPT { return begin(); }
const_iterator cend() const BOOST_NOEXCEPT { return cbegin(); }
BOOST_CXX14_CONSTEXPR iterator end() BOOST_NOEXCEPT { return begin(); }
BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT { return begin(); }
BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return cbegin(); }

// reverse iterator support
typedef std::reverse_iterator<iterator> reverse_iterator;
Expand Down
7 changes: 6 additions & 1 deletion test/array0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ void RunTests()
BOOST_TEST ( const_test_case.begin() == const_test_case.end());
BOOST_TEST ( const_test_case.cbegin() == const_test_case.cend());

BOOST_TEST ( test_case.begin() != const_test_case.begin() );
// BOOST_TEST ( test_case.begin() != const_test_case.begin() );
//
// TR1 specified that begin() must return a unique value for zero-sized
// arrays. However, this makes constexpr unimplementable, and all standard
// libraries have converged on using nullptr instead (see LWG issue 2157.)

if( test_case.data() == const_test_case.data() ) {
// Value of data is unspecified in TR1, so no requirement this test pass or fail
// However, it must compile!
Expand Down

0 comments on commit 89f09e3

Please sign in to comment.