Skip to content

Commit

Permalink
master: cppad_vector_itr.hpp: Attempt to fix CppAD::vector iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbell committed Aug 10, 2024
1 parent 218806f commit bcb0a1a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions example/utility/cppad_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ bool CppAD_vector(void)
const vector<Scalar> 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);
Expand All @@ -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<Scalar>::iterator iterator;
Expand Down
21 changes: 7 additions & 14 deletions include/cppad/local/utility/cppad_vector_itr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
// SPDX-FileContributor: 2003-22 Bradley M. Bell
// SPDX-FileContributor: 2003-24 Bradley M. Bell
// ----------------------------------------------------------------------------

# include <cstddef>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -427,14 +427,7 @@ Source
template <class Type> CPPAD_VECTOR_ITR<Type> operator+(
typename CPPAD_VECTOR_ITR<Type>::difference_type n ,
const CPPAD_VECTOR_ITR<Type>& other ) noexcept
{ return
CPPAD_VECTOR_ITR<Type>(other.data_, other.length_, n + other.index_ );
}
template <class Type> CPPAD_VECTOR_ITR<Type> operator-(
typename CPPAD_VECTOR_ITR<Type>::difference_type n ,
const CPPAD_VECTOR_ITR<Type>& other ) noexcept
{ return
CPPAD_VECTOR_ITR<Type>(other.data_, other.length_, n - other.index_ );
{ return other + n;
}
// END_BINARY_OP

Expand Down
6 changes: 0 additions & 6 deletions test_more/general/cppad_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -85,7 +84,6 @@ bool test_sort(void)
//
return ok;
}
# endif


} // END_EMPTY_NAMESPACE
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion user_guide.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -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.}
Expand Down

0 comments on commit bcb0a1a

Please sign in to comment.