Skip to content

Commit

Permalink
copy_n: return canonical iterator instead of pair (#4633)
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Sokolov authored and GitHub Enterprise committed Jun 27, 2024
1 parent 049cdff commit 472c990
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 599 deletions.
4 changes: 0 additions & 4 deletions groups/bsl/bsl+bslhdrs/bsl_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ BSLS_IDENT("$Id: $")

#include <bslstl_algorithm.h>

#ifndef BDE_OPENSOURCE_PUBLICATION // STP
#include <bslstp_exalgorithm.h>
#endif // BDE_OPENSOURCE_PUBLICATION -- STP

#endif

// ----------------------------------------------------------------------------
Expand Down
11 changes: 3 additions & 8 deletions groups/bsl/bslim/bslim_bslstandardheadertest.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,17 +972,12 @@ int main(int argc, char *argv[])
out.push_back(i + 10);
}

ConstIterator EXPECTED_IN = in.cbegin() + NUM_ITEMS_TO_COPY;
Iterator EXPECTED_OUT = out.begin() + NUM_ITEMS_TO_COPY;
ConstIterator EXPECTED_OUT = out.begin() + NUM_ITEMS_TO_COPY;

bsl::pair<ConstIterator, Iterator> result =
Iterator result =
bsl::copy_n(in.cbegin(), NUM_ITEMS_TO_COPY, out.begin());

ConstIterator resultIn = result.first;
Iterator resultOut = result.second;

ASSERT(EXPECTED_IN == resultIn);
ASSERT(EXPECTED_OUT == resultOut);
ASSERT(EXPECTED_OUT == result);

for (size_t i = 0; i < NUM_ITEMS_TO_COPY; ++i) {
ASSERTV(in[i], out[i], in[i] == out[i]);
Expand Down
34 changes: 29 additions & 5 deletions groups/bsl/bslstl/bslstl_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,8 @@ namespace bsl {
using std::any_of;
using std::copy_if;

// 'copy_n' is implemented separately in 'bslstp_exalgorithm' for backwards
// compatibility with the previous STLport definition (which differs from
// the platform implementation).
//
// using std::(copy_n);
using std::copy_n;
#define BSLSTL_ALGORITHM_COPY_N_IS_ALIASED

using std::find_if_not;
using std::is_heap;
Expand Down Expand Up @@ -487,6 +484,21 @@ namespace ranges {

} // close namespace bsl



#ifndef BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
namespace bsl {
template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
inline
t_OUTPUT_ITERATOR copy_n(t_INPUT_ITERATOR first,
t_SIZE count,
t_OUTPUT_ITERATOR result);
// Copy the specified 'count' elements from the specified 'first' to the
// specified 'result'. Return an iterator pointing past the last copied
// element in the output range.
} // close namespace bsl
#endif // BSLSTL_ALGORITHM_COPY_N_IS_ALIASED

// ============================================================================
// INLINE DEFINITIONS
// ============================================================================
Expand Down Expand Up @@ -672,6 +684,18 @@ bsl::search(FORWARD_ITERATOR first,
}
#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_OVERLOAD

#ifndef BSLSTL_ALGORITHM_COPY_N_IS_ALIASED
template <class t_INPUT_ITERATOR, class t_SIZE, class t_OUTPUT_ITERATOR>
inline
t_OUTPUT_ITERATOR bsl::copy_n(t_INPUT_ITERATOR first,
t_SIZE count,
t_OUTPUT_ITERATOR result)
{
return BloombergLP::bslstl::AlgorithmUtil::copyN(first,
count,
result);
}
#endif // BSLSTL_ALGORITHM_COPY_N_IS_ALIASED

#endif // INCLUDED_BSLSTL_ALGORITHM

Expand Down
25 changes: 0 additions & 25 deletions groups/bsl/bslstp/bslstp_exalgorithm.cpp

This file was deleted.

179 changes: 0 additions & 179 deletions groups/bsl/bslstp/bslstp_exalgorithm.h

This file was deleted.

Loading

0 comments on commit 472c990

Please sign in to comment.