Skip to content

Commit

Permalink
unordered_erase overload for dynarray moved to range_algo.h, simplifi…
Browse files Browse the repository at this point in the history
…ed to_dynarray

Also added ../ to an include.
to_dynarray no longer niebloid
  • Loading branch information
OleErikPeistorpet committed Jun 9, 2024
1 parent b43ba7a commit b28a126
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion auxi/dynarray_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)


#include "util.h" // for from_range
#include "../util.h" // for from_range

#include <cstdint> // for uintptr_t
#include <stdexcept>
Expand Down
19 changes: 5 additions & 14 deletions dynarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,18 @@
namespace oel
{

struct _toDynarrayFn
{
template< typename Alloc = allocator<> >
constexpr auto operator()(Alloc a = {}) const
{
return _detail::ToDynarrPartial<Alloc>{std::move(a)};
}
};
//! `r | to_dynarray()` is equivalent to `r | std::ranges::to<dynarray>()`
/**
* Example, convert array of std::bitset to `dynarray<std::string>`:
@code
std::bitset<8> arr[] {3, 5, 7, 11};
auto result = arr | view::transform(OEL_MEMBER_FN(to_string)) | to_dynarray();
@endcode */
inline constexpr _toDynarrayFn to_dynarray;

//! Overloads generic unordered_erase(RandomAccessContainer &, Integral) (in range_algo.h)
template< typename T, typename A > inline
void unordered_erase(dynarray<T, A> & d, ptrdiff_t index) { d.unordered_erase(d.begin() + index); }

template< typename Alloc = allocator<> >
constexpr auto to_dynarray(Alloc a = {})
{
return _detail::ToDynarrPartial<Alloc>{std::move(a)};
}

//! dynarray is trivially relocatable if Alloc is
template< typename T, typename Alloc >
Expand Down
3 changes: 3 additions & 0 deletions range_algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ constexpr void unordered_erase(RandomAccessContainer & c, Integral index)
c[index] = std::move(c.back());
c.pop_back();
}
//! See unordered_erase(RandomAccessContainer &, Integral) or dynarray::unordered_erase
template< typename T, typename A > inline
void unordered_erase(dynarray<T, A> & d, ptrdiff_t index) { d.unordered_erase(d.begin() + index); }

/**
* @brief Erase from container all elements for which predicate returns true
Expand Down

0 comments on commit b28a126

Please sign in to comment.