10 #define BOOST_TEST_MODULE ( SortByPointers_test )
11 #include <boost/test/unit_test.hpp>
19 #include <type_traits>
24 template <
typename Data>
36 std::vector<int> data = { 8, -7, 5, 9, -2 };
40 auto sortedData = data;
41 std::sort(sortedData.begin(), sortedData.end(), absSorter);
44 [absSorter](
auto& coll){ std::sort(coll.begin(), coll.end(), absSorter); }
47 BOOST_CHECK_EQUAL_COLLECTIONS
48 (data.cbegin(), data.cend(), sortedData.cbegin(), sortedData.cend());
56 std::vector<int> data = { 8, -7, 5 };
58 std::vector<int*> expectedDataPtr = { &(data[0]), &(data[1]), &(data[2]) };
63 std::is_same<std::decay_t<decltype(dataPtr)>, std::vector<int*>>(),
64 "Unexpected data type from makePointerVector()");
66 BOOST_CHECK_EQUAL_COLLECTIONS(
67 dataPtr.cbegin(), dataPtr.cend(),
68 expectedDataPtr.cbegin(), expectedDataPtr.cend()
77 std::vector<int> data = { 1, 2, 3, 4 };
79 std::vector<int*>
const dataPtr
80 = { &(data[2]), &(data[3]), &(data[0]), &(data[1]) };
81 std::vector<int> expectedMovedData = { 3, 4, 1, 2 };
83 std::vector<int> movedData;
86 BOOST_CHECK_EQUAL_COLLECTIONS(
87 movedData.cbegin(), movedData.cend(),
88 expectedMovedData.cbegin(), expectedMovedData.cend()
bool operator()(Data a, Data b) const
Silly utility to sort vectors indirectly.
auto makePointerVector(Coll &coll)
Creates a STL vector with pointers to data from another collection.
bool operator()(Data const *a, Data const *b) const
void test_makePointerVector()
void test_SortByPointers()
void SortByPointers(Coll &coll, Sorter sorter)
Applies sorting indirectly, minimizing data copy.
void test_MoveFromPointers()
void MoveFromPointers(Coll &dest, PtrColl &src)
Moves the content from a collection of pointers to one of data.