I am new to Eric Niebler's ranges-v3 library and I would like to solve the following simple problem:
I have a std::map
containing the following:
std::map<std::string, int> map = {
{"THIS", 1}, {"IS", 2}, {"A", 3}, {"TEST", 4}, {"WITH", 5}, {"MORE", 6}, {"KEYS", 7}
};
I have a std::vector
containing a set of keys as follows:
std::vector<std::string> vec = {
"THIS", "IS", "A", "TEST"
};
How do I use the library (ideally using the pipe composition syntax) to filter out pairs from the map containing the keys in the vector and transcode the resultant view to a std::set<std::pair<std::string, int>>
. Additionally to make the transcode interesting, make sure that the values in the map need to be odd. In this case the range code should:
use these keys:
THIS,IS,A,TEST,
against this map
{A,3},{IS,2},{KEYS,7},{MORE,6},{TEST,4},{THIS,1},{WITH,5},
with an odd map value predicate - produce the following result as a different type of container std::set
{A,3},{THIS,1},
This should be relatively straightforward but I cannot figure out the new syntax. Also any insight about eager vs lazy would be a plus to help me understand.
The following stripped down coliru example shows what I am looking for.