Skip to content

Commit 62cd734

Browse files
committed
removed map_keys and map_values
1 parent df1df00 commit 62cd734

2 files changed

Lines changed: 0 additions & 86 deletions

File tree

include/map.h

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/map_test.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,6 @@ TEST(MapTest, AccessOperator)
6464
EXPECT_EQ(0, persons["john"]);
6565
}
6666

67-
TEST(MapTest, MapValues)
68-
{
69-
const map<std::string, int> persons({{"jake", 32}, {"mary", 26}, {"david", 40}});
70-
const auto mapped = persons.map_values<std::string>([](const int& age) {
71-
return std::to_string(age);
72-
});
73-
74-
EXPECT_EQ(vector<std::string>({"40", "32", "26"}), mapped);
75-
}
76-
77-
TEST(MapTest, MapKeys)
78-
{
79-
const map<std::string, int> persons({{"jake", 32}, {"mary", 26}, {"david", 40}});
80-
const auto mapped = persons.map_keys<char>([](const std::string& name) {
81-
return name[0];
82-
});
83-
84-
EXPECT_EQ(vector<char>({'d', 'j', 'm'}), mapped);
85-
}
86-
8767
TEST(MapTest, MapTo)
8868
{
8969
const map<std::string, int> persons({{"jake", 32}, {"mary", 26}, {"david", 40}});

0 commit comments

Comments
 (0)