Skip to content

Commit 8831b44

Browse files
committed
Fixing forceful reserve before assignment.
1 parent 06bd32a commit 8831b44

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

include/comms/util/details/AssignHelper.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class AssignHelper
9797
template <typename T, typename TIter, typename... TParams>
9898
static void assignInternal(T& obj, TIter from, TIter to, UseAssignTag<TParams...>)
9999
{
100+
using ObjType = typename std::decay<decltype(obj)>::type;
101+
auto len = static_cast<std::size_t>(std::distance(from, to));
102+
reserveInternal(obj, len, ReserveTag<ObjType>());
100103
obj.assign(from, to);
101104
}
102105

@@ -132,10 +135,8 @@ class AssignHelper
132135
using ObjType = typename std::decay<decltype(obj)>::type;
133136
using ConstPointerType = typename ObjType::const_pointer;
134137
using PointerType = typename ObjType::pointer;
135-
auto len = static_cast<std::size_t>(std::distance(from, to));
136138
auto fromPtr = const_cast<PointerType>(reinterpret_cast<ConstPointerType>(&(*from)));
137-
auto toPtr = fromPtr + len;
138-
reserveInternal(obj, len, ReserveTag<ObjType>());
139+
auto toPtr = fromPtr + std::distance(from, to);
139140
assignInternal(obj, fromPtr, toPtr, UsePtrSizeConstructorTag<TParams...>());
140141
}
141142

0 commit comments

Comments
 (0)