Mapping a record type to a vector of field values:
unordered_map<string, vector<string>> input_records;
string rec_type {"name"};
vector<string> fields { "field 1", "field 2", "field 3" };
I want to copy fields to input_records[rec_type]. The following doesn't work:
_input_records[rec_type].insert(rec_deq.begin(), rec_deq.end());
Yet the boost documentation for unordered_map contains this:
template<typename InputIterator>
void insert(InputIterator first, InputIterator last);
Inserts a range of elements into the container. Elements are inserted if and only if there is no element in the container with an equivalent key.
Throws:
When inserting a single element, if an exception is thrown by an operation other than a call to hasher the function has no effect.
Notes:
Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.
Pointers and references to elements are never invalidated.
(Writing this, I realize that probably the InputIterator points to a sequence of key/value pairs, each of which is to be inserted into the Map. So, wrong method.)
How best can one instantiate and populate the vector at input_record[rec_type]? Once populated, the vector won't be modified. Is it as simple as input_record[rec_type] = fields? Do, or can, "move semantics" apply in this situation?
input_record[rec_type] = fields?" Did you try it? ;-o For move semantics, replacefieldswith a temporary (easier in C++11). "Emplacing" the new value is slightly better than moving it, but unlikely to be significant given your data types.