MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ merge_prefixed()

template<typename K, typename V, typename Compare = std::less<K>>
bool MayaFlux::Memory::FlatMap< K, V, Compare >::merge_prefixed ( const FlatMap< K, V, Compare > & other,
std::string_view prefix,
std::string & error,
bool replace = false )
inline

Adds every entry of other under a name prefix.

For maps keyed by name, so a catalog can be combined with another without their names colliding.

Parameters
prefixPrepended to each key; empty keeps the keys.
errorReceives the first colliding name when false is returned.
replaceTrue to overwrite existing entries instead of failing.
Returns
true on success. A failed merge leaves this map unchanged.

Definition at line 106 of file FlatMap.hpp.

109 {
110 if (!replace) {
111 for (const auto& entry : other.m_items) {
112 const std::string target = std::string(prefix) + entry.first;
113 if (find(target) != end()) {
114 error = "already has an entry named " + target;
115 return false;
116 }
117 }
118 }
119 for (const auto& entry : other.m_items) {
121 }
122 return true;
123 }
const_iterator end() const noexcept
Definition FlatMap.hpp:27
bool insert_or_assign(const K &key, V value)
Sets the value for key, adding the entry if it is absent.
Definition FlatMap.hpp:44
const_iterator find(const K &key) const
The entry for key, or end() when absent.
Definition FlatMap.hpp:32
std::vector< value_type > m_items
Definition FlatMap.hpp:135
Map kept as one sorted vector, cheap to copy.
Definition FlatMap.hpp:21