From bcb0a1a69ecbd22b1420a84a8a05dbb98e298280 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Sat, 10 Aug 2024 06:51:07 -0700 Subject: [PATCH] master: cppad_vector_itr.hpp: Attempt to fix CppAD::vector iterators. --- CMakeLists.txt | 2 +- example/utility/cppad_vector.cpp | 7 ------- .../cppad/local/utility/cppad_vector_itr.hpp | 21 +++++++------------ test_more/general/cppad_vector.cpp | 6 ------ user_guide.xrst | 2 +- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 086441854..6a2334283 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ IF( POLICY CMP0054 ) ENDIF( POLICY CMP0054 ) # # cppad_version is used by version.sh to get the version number. -SET(cppad_version "20240809") +SET(cppad_version "20240810") SET(cppad_url "https://coin-or.github.io/CppAD" ) SET(cppad_description "Differentiation of C++ Algorithms" ) IF( NOT DEFINED CMAKE_BUILD_TYPE) diff --git a/example/utility/cppad_vector.cpp b/example/utility/cppad_vector.cpp index b766609fa..e852fabb5 100644 --- a/example/utility/cppad_vector.cpp +++ b/example/utility/cppad_vector.cpp @@ -144,9 +144,6 @@ bool CppAD_vector(void) const vector cvec = vec; // sort of vec (will reverse order of elements for this case) -# if ! defined(_MSC_VER) && ! CPPAD_CXX_IS_XCODE - // 2DO: Determine why this test fails with Visual Studio 2019 - // and with Xcode version of AppleClang-15.0.0 std::sort(vec.begin(), vec.end()); for(size_t i = 0; i < n ; ++i) ok &= vec[i] == Scalar(i + 1); @@ -155,10 +152,6 @@ bool CppAD_vector(void) std::sort(other.data(), other.data() + other.size()); for(size_t i = 0; i < n ; ++i) ok &= other[i] == Scalar(i + 1); -# endif - // Incase the test above was not done - for(size_t i = 0; i < n ; ++i) - vec[i] = Scalar(i + 1); // // test direct use of iterator and const_iterator typedef vector::iterator iterator; diff --git a/include/cppad/local/utility/cppad_vector_itr.hpp b/include/cppad/local/utility/cppad_vector_itr.hpp index e038ec564..824f8e249 100644 --- a/include/cppad/local/utility/cppad_vector_itr.hpp +++ b/include/cppad/local/utility/cppad_vector_itr.hpp @@ -2,7 +2,7 @@ # define CPPAD_LOCAL_UTILITY_CPPAD_VECTOR_ITR_HPP // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later // SPDX-FileCopyrightText: Bradley M. Bell -// SPDX-FileContributor: 2003-22 Bradley M. Bell +// SPDX-FileContributor: 2003-24 Bradley M. Bell // ---------------------------------------------------------------------------- # include @@ -305,21 +305,21 @@ Source { check_element(); return (*data_)[index_]; } - const Type& operator[](difference_type n) + const Type& operator[](difference_type n) const { return *(*this + n); } - const Type& operator[](size_t n) + const Type& operator[](size_t n) const { return *( *this + difference_type(n) ); } # else - Type& operator*(void) + Type& operator*(void) const { check_element(); return (*data_)[index_]; } - Type& operator[](difference_type n) + Type& operator[](difference_type n) const { return *(*this + n); } - Type& operator[](size_t n) + Type& operator[](size_t n) const { return *( *this + difference_type(n) ); } # endif @@ -427,14 +427,7 @@ Source template CPPAD_VECTOR_ITR operator+( typename CPPAD_VECTOR_ITR::difference_type n , const CPPAD_VECTOR_ITR& other ) noexcept -{ return - CPPAD_VECTOR_ITR(other.data_, other.length_, n + other.index_ ); -} -template CPPAD_VECTOR_ITR operator-( - typename CPPAD_VECTOR_ITR::difference_type n , - const CPPAD_VECTOR_ITR& other ) noexcept -{ return - CPPAD_VECTOR_ITR(other.data_, other.length_, n - other.index_ ); +{ return other + n; } // END_BINARY_OP diff --git a/test_more/general/cppad_vector.cpp b/test_more/general/cppad_vector.cpp index d0d13e47b..8506280b6 100644 --- a/test_more/general/cppad_vector.cpp +++ b/test_more/general/cppad_vector.cpp @@ -68,7 +68,6 @@ bool test_reverse(void) return ok; } -# if ! defined(_MSC_VER) && ! CPPAD_CXX_IS_XCODE bool test_sort(void) { // copy requires a random access iterator bool ok = true; @@ -85,7 +84,6 @@ bool test_sort(void) // return ok; } -# endif } // END_EMPTY_NAMESPACE @@ -96,11 +94,7 @@ bool cppad_vector(void) ok &= test_find(); ok &= test_copy(); ok &= test_reverse(); -# if ! defined(_MSC_VER) && ! CPPAD_CXX_IS_XCODE - // 2DO: Determine why this test fails with Visual Studio 2019 - // and with Xcode version of AppleClang-15.0.0 ok &= test_sort(); -# endif // return ok; } diff --git a/user_guide.xrst b/user_guide.xrst index 167c75af9..6513603dd 100644 --- a/user_guide.xrst +++ b/user_guide.xrst @@ -13,7 +13,7 @@ {xrst_comment BEGIN: Before changing see new_release.sh and check_version.sh} -cppad-20240809: CppAD User's Manual +cppad-20240810: CppAD User's Manual ################################### {xrst_comment The scripts bin/check_version.sh and bin/new_release.sh edit version numbers in tables below.}