Created
June 27, 2019 06:13
-
-
Save grisumbras/13a249d62c5c29a38191a4f13fe6f776 to your computer and use it in GitHub Desktop.
Revisions
-
grisumbras created this gist
Jun 27, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ template <class Vector, class ProtoAllocator> auto require(Vector &&vec, std::execution::allocator_t<Allocator> prop) { using V = std::decay_t<Vector>; using SourceAllocator = typename V::allocator_type; using ValueType = typename V::value_type; using ProtoTraits = std::allocator_traits<ProtoAllocator>; using TargetAllocator = typename ProtoTraits::template rebind_alloc<ValueType>; TargetAllocator const target_alloc = prop.value(); if constexpr (std::is_same_v<SourceAllocator, TargetAllocator>) { if (vec.get_allocator() == target_alloc) { return vec; } else { return V(vec.begin(), vec.end(), target_alloc); } } else { return std::vector<ValueType, TargetAllocator>(vec.begin(), vec.end(), target_alloc); } } template <class Vector, class ProtoAllocator> auto switch_allocator_for_vector(Vector &&vec, ProtoAllocator alloc) { return std::require(std::forward<Vector>(vec), std::execution::allocator(alloc)); }