/* * Copyright (C) 2015 Cloudius Systems, Ltd. */ #pragma once #include template struct value_difference { Tp left_value; Tp right_value; value_difference(const Tp& left_value_, const Tp& right_value_) : left_value(left_value_) , right_value(right_value_) { } }; template struct map_difference { // Entries in left map whose keys don't exist in the right map. std::map entries_only_on_left; // Entries in right map whose keys don't exist in the left map. std::map entries_only_on_right; // Entries that appear in both maps with the same value. std::map entries_in_common; // Entries that appear in both maps but have different values. std::map, Compare> entries_differing; map_difference(const Compare& cmp, const Alloc& alloc) : entries_only_on_left{cmp, alloc} , entries_only_on_right{cmp, alloc} , entries_in_common{cmp, alloc} , entries_differing{cmp, alloc} { } }; template inline map_difference difference(const std::map& left, const std::map& right, const Compare& key_comp, const Alloc& alloc) { map_difference diff{key_comp, alloc}; diff.entries_only_on_right = right; for (auto&& kv : left) { auto&& left_key = kv.first; auto&& it = right.find(left_key); if (it != right.end()) { diff.entries_only_on_right.erase(left_key); auto&& left_value = kv.second; auto&& right_value = it->second; if (left_value == right_value) { diff.entries_in_common.emplace(kv); } else { value_difference value_diff{left_value, right_value}; diff.entries_differing.emplace(left_key, std::move(value_diff)); } } else { diff.entries_only_on_left.emplace(kv); } } return diff; } template inline map_difference difference(const std::map& left, const std::map& right) { return difference(left, right, left.key_comp(), left.get_allocator()); }