-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
For many mutable operations, there is a transform operation that can be
applied to perform the copy with the mutation in a more efficient manner. (source)
Is that so? It would be good to cover that in the example. For the more common case, where the transform is implemented in terms of the inplace mutation, it would be good to have an overload with just one argument. It would also make sense to swap the positions of the two arguments:
template <class Inplace, class Transform>
auto write(Inplace inplace, Transform transform) -> element_type&;
template <class Inplace>
auto write(Inplace inplace) -> element_type& {
return write(inplace, [&](const element_type& x) {
element_type tmp = x;
inplace(tmp);
return tmp;
});
}It is error prone to provide both inplace and transform. Inconsistencies may sneak in, as the example proves:
When you want to remove the last element of the document (index == size()), you will observe different behaviour depending on the usage count.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels