mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 01:06:44 +08:00
Reserve the container size across remappings
This commit is contained in:
parent
de40af0927
commit
22ce1840b9
@ -441,6 +441,25 @@ template <typename T, typename M>
|
|||||||
using container_mapping_tag_of_t =
|
using container_mapping_tag_of_t =
|
||||||
container_mapping_tag<is_empty_mapped<T, M>::value, can_reuse<T, M>::value>;
|
container_mapping_tag<is_empty_mapped<T, M>::value, can_reuse<T, M>::value>;
|
||||||
|
|
||||||
|
/// Deduces to a true type if the given parameter T supports a `reserve` method
|
||||||
|
template <typename From, typename To, typename = void>
|
||||||
|
struct is_reservable_from : std::false_type {};
|
||||||
|
template <typename From, typename To>
|
||||||
|
struct is_reservable_from<From, To,
|
||||||
|
traits::void_t<decltype(std::declval<To>().reserve(
|
||||||
|
std::declval<From>().size()))>> : std::true_type {
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Dest, typename Source>
|
||||||
|
void reserve_if(std::true_type, Dest&& dest, Source&& source) {
|
||||||
|
// Reserve the mapped size
|
||||||
|
dest.reserve(source.size());
|
||||||
|
}
|
||||||
|
template <typename Dest, typename Source>
|
||||||
|
void reserve_if(std::false_type, Dest&&, Source&&) noexcept {
|
||||||
|
// We do nothing here, since the container doesn't support reserving
|
||||||
|
}
|
||||||
|
|
||||||
/// We create a new container, which may hold the resulting type
|
/// We create a new container, which may hold the resulting type
|
||||||
template <typename M, typename T>
|
template <typename M, typename T>
|
||||||
auto remap_container(container_mapping_tag<false, false>, M&& mapper,
|
auto remap_container(container_mapping_tag<false, false>, M&& mapper,
|
||||||
@ -456,9 +475,10 @@ auto remap_container(container_mapping_tag<false, false>, M&& mapper,
|
|||||||
auto remapped = rebind_container<mapped_type_from_t<T, M>>(container);
|
auto remapped = rebind_container<mapped_type_from_t<T, M>>(container);
|
||||||
|
|
||||||
// We try to reserve the original size from the source
|
// We try to reserve the original size from the source
|
||||||
// container to the destination container.
|
// container inside the destination container.
|
||||||
// TODO Re-implement this
|
reserve_if(
|
||||||
// traits::detail::reserve_if_reservable(remapped, container.size());
|
is_reservable_from<std::decay_t<T>, std::decay_t<decltype(remapped)>>{},
|
||||||
|
remapped, container);
|
||||||
|
|
||||||
// Perform the actual value remapping from the source to
|
// Perform the actual value remapping from the source to
|
||||||
// the destination.
|
// the destination.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user