@@ -57,72 +57,6 @@ class map
5757 {
5858 }
5959
60- // Performs the functional `map` algorithm for keys, in which every element of the resulting
61- // vector is the output of applying the transform function on every key of this instance.
62- //
63- // example:
64- // const fcpp::map<std::string, int> ages({{"jake", 32}, {"mary", 26}, {"david", 40}});
65- // const auto initials = ages.map_keys<char>([](const auto& name) {
66- // return name[0];
67- // });
68- //
69- // outcome:
70- // initials -> fcpp::vector<char>({'d', 'j', 'm'})
71- //
72- // is equivalent to:
73- // const fcpp::map<std::string, int> ages({{"jake", 32}, {"mary", 26}, {"david", 40}});
74- // fcpp::vector<char> initials;
75- // for (const auto& element : ages) {
76- // initials.insert_back(element.first[0]);
77- // }
78- #ifdef CPP17_AVAILABLE
79- template <typename U, typename Transform, typename = std::enable_if_t <std::is_invocable_r_v<U, Transform, TKey>>>
80- #else
81- template <typename U, typename Transform>
82- #endif
83- vector<U> map_keys (Transform && transform) const
84- {
85- vector<U> transformed;
86- transformed.reserve (size ());
87- for (const auto & element : m_map) {
88- transformed.insert_back (transform (element.first ));
89- }
90- return transformed;
91- }
92-
93- // Performs the functional `map` algorithm for values, in which every element of the resulting
94- // vector is the output of applying the transform function on every value of this instance.
95- //
96- // example:
97- // const fcpp::map<std::string, int> ages({{"jake", 32}, {"mary", 26}, {"david", 40}});
98- // const auto labels = ages.map_values<std::string>([](const auto& age) {
99- // return std::to_string(age);
100- // });
101- //
102- // outcome:
103- // labels -> fcpp::vector<std::string>({"40", "32", "26"})
104- //
105- // is equivalent to:
106- // const fcpp::map<std::string, int> ages({{"jake", 32}, {"mary", 26}, {"david", 40}});
107- // fcpp::vector<std::string> labels;
108- // for (const auto& element : ages) {
109- // labels.insert_back(std::to_string(element.second));
110- // }
111- #ifdef CPP17_AVAILABLE
112- template <typename U, typename Transform, typename = std::enable_if_t <std::is_invocable_r_v<U, Transform, TValue>>>
113- #else
114- template <typename U, typename Transform>
115- #endif
116- vector<U> map_values (Transform && transform) const
117- {
118- vector<U> transformed;
119- transformed.reserve (size ());
120- for (const auto & element : m_map) {
121- transformed.insert_back (transform (element.second ));
122- }
123- return transformed;
124- }
125-
12660 // Performs the functional `map` algorithm from one map to another map, in which every key/value
12761 // pair of the resulting map is the output of applying the transform function on every key/value
12862 // pair of this instance. If two source elements produce equivalent result keys, the first
0 commit comments