Skip to content

Instantly share code, notes, and snippets.

@benlau
Last active March 15, 2019 06:55
Show Gist options
  • Save benlau/bc2f458a9e85f6a1a1d25c1505a07a49 to your computer and use it in GitHub Desktop.
Save benlau/bc2f458a9e85f6a1a1d25c1505a07a49 to your computer and use it in GitHub Desktop.
template <typename Object, typename Source, typename Iteratee>
inline Object assignWith(Object& object, const Source & source, Iteratee iteratee ) {
using source_info = _::Private::key_value_info<Source>;
using object_info = _::Private::key_value_info<Object>;
_underline_static_assert_is_iteratee_invokable("_::assignWith: ", (_::Private::is_invokable5<Iteratee,
typename object_info::value_type,
typename source_info::value_type,
typename source_info::key_type,
Object, Source>::value));
forIn(source, [&](const typename source_info::value_type& value,
const typename source_info::key_type& key) {
auto ret = Private::invoke(iteratee,
Private::read(object, key),
value,
key,
object,
source);
Private::write(object, key, ret);
});
return object;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment