10 #ifndef LARCOREALG_COREUTILS_SORTBYPOINTER_H 11 #define LARCOREALG_COREUTILS_SORTBYPOINTER_H 23 #include <type_traits> 30 template <
typename Coll,
typename PtrColl>
43 template <
typename Coll>
60 template <
typename Coll,
typename PtrColl>
94 template <
typename Coll,
typename Sorter>
111 template <
typename Coll,
typename Sorter>
126 template <
typename Coll,
typename =
void>
133 using pointer_type = decltype(&*
begin(coll));
134 using ptr_coll_t = std::vector<pointer_type>;
136 auto const n = coll.size();
143 std::transform(
begin(coll),
end(coll), std::back_inserter(ptrs),
144 [](
auto& obj){
return &obj; });
153 template <
typename Coll>
155 <Coll,
std::enable_if_t<util::is_unique_ptr_v<typename Coll::value_type>>>
163 using unique_ptr_t =
typename coll_t::value_type;
164 using value_type =
typename unique_ptr_t::element_type;
165 using pointer_type = std::add_pointer_t<value_type>;
166 using ptr_coll_t = std::vector<pointer_type>;
168 static_assert(util::is_unique_ptr_v<unique_ptr_t>);
171 auto const n =
size(coll);
178 std::transform(coll.begin(), coll.end(), std::back_inserter(ptrs),
179 [](
auto& obj){
return obj.get(); });
197 template <
typename Coll>
203 template <
typename Coll,
typename Sorter>
233 template <
typename Coll,
typename Sorter>
236 using Collection_t = Coll;
237 using UPtr_t =
typename Collection_t::value_type;
239 static_assert(util::is_unique_ptr_v<UPtr_t>);
258 for (
auto const& dataPtr: ptrs) {
259 std::size_t
const originalIndex = ptrIndex.at(dataPtr);
260 sorted.emplace_back(
std::move(coll[originalIndex]));
275 template <
typename Coll,
typename PtrColl>
277 {
for (
auto&& ptr: src) dest.push_back(
std::move(*ptr)); }
280 template <
typename Coll,
typename PtrColl>
290 template <
typename Data,
typename PtrColl>
292 static void move(std::vector<Data>&
dest, PtrColl& src)
295 dest.reserve(src.size());
306 #endif // LARCOREALG_COREUTILS_SORTBYPOINTER_H end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static void move(std::vector< Data > &dest, PtrColl &src)
static void move(Coll &dest, PtrColl &src)
Namespace for general, non-LArSoft-specific utilities.
Provides util::makeValueIndex() helper function.
auto makePointerVector(Coll &coll)
Creates a STL vector with pointers to data from another collection.
void SortUniquePointers(Coll &coll, Sorter &&sorter)
Sorts a vector of unique pointers using a C pointer sorter.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void SortByPointers(Coll &coll, Sorter sorter)
Applies sorting indirectly, minimizing data copy.
static auto make(Coll &coll)
void moveFromPointersImplBase(Coll &dest, PtrColl &src)
static auto make(Coll &coll)
void MoveFromPointers(Coll &dest, PtrColl &src)
Moves the content from a collection of pointers to one of data.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
decltype(auto) makeValueIndex(Coll const &coll, Extractor getter)
Returns a map of value to index.