10 #ifndef LARCOREALG_COREUTILS_SORTBYPOINTER_H 11 #define LARCOREALG_COREUTILS_SORTBYPOINTER_H 19 #include <type_traits> 26 template <
typename Coll,
typename PtrColl>
39 template <
typename Coll>
56 template <
typename Coll,
typename PtrColl>
90 template <
typename Coll,
typename Sorter>
102 template <
typename Coll>
106 using value_type =
typename coll_t::value_type;
107 using pointer_type = std::add_pointer_t<value_type>;
108 using ptr_coll_t = std::vector<pointer_type>;
110 auto const n = coll.size();
117 std::transform(coll.begin(), coll.end(), std::back_inserter(ptrs),
118 [](
auto& obj){
return &obj; });
126 template <
typename Coll,
typename Sorter>
150 coll = std::move(sorted);
159 template <
typename Coll,
typename PtrColl>
161 {
for (
auto&& ptr: src) dest.push_back(std::move(*ptr)); }
164 template <
typename Coll,
typename PtrColl>
166 static void move(Coll& dest, PtrColl& src)
174 template <
typename Data,
typename PtrColl>
176 static void move(std::vector<Data>& dest, PtrColl& src)
179 dest.reserve(src.size());
190 #endif // LARCOREALG_COREUTILS_SORTBYPOINTER_H
static void move(std::vector< Data > &dest, PtrColl &src)
static void move(Coll &dest, PtrColl &src)
Namespace for general, non-LArSoft-specific utilities.
auto makePointerVector(Coll &coll)
Creates a STL vector with pointers to data from another collection.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void SortByPointers(Coll &coll, Sorter sorter)
Applies sorting indirectly, minimizing data copy.
void moveFromPointersImplBase(Coll &dest, PtrColl &src)
void MoveFromPointers(Coll &dest, PtrColl &src)
Moves the content from a collection of pointers to one of data.