Skip to content

Commit c079ddb

Browse files
committed
refactor: use std::pair instead of std::tuple
1 parent 9756a4a commit c079ddb

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

include/ada/url_search_params-inl.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,39 @@ namespace ada {
1818

1919
inline void url_search_params::append(const std::string_view key,
2020
const std::string_view value) {
21-
params.emplace_back(std::string(key), std::string(value));
21+
params.emplace_back(key, value);
2222
}
2323

2424
inline size_t url_search_params::size() const noexcept { return params.size(); }
2525

2626
inline std::optional<std::string_view> url_search_params::get(
2727
const std::string_view key) {
28-
auto entry = std::find_if(params.begin(), params.end(), [&key](auto& param) {
29-
return std::get<0>(param) == key;
30-
});
28+
auto entry = std::find_if(params.begin(), params.end(),
29+
[&key](auto& param) { return param.first == key; });
3130

3231
if (entry == params.end()) {
3332
return std::nullopt;
3433
}
3534

36-
return std::get<1>(*entry);
35+
return entry->second;
3736
}
3837

3938
inline std::vector<std::string> url_search_params::get_all(
4039
const std::string_view key) {
4140
std::vector<std::string> out{};
4241

4342
for (auto& param : params) {
44-
if (std::get<0>(param) == key) {
45-
out.emplace_back(std::get<1>(param));
43+
if (param.first == key) {
44+
out.emplace_back(param.second);
4645
}
4746
}
4847

4948
return out;
5049
}
5150

5251
inline bool url_search_params::has(const std::string_view key) noexcept {
53-
auto entry = std::find_if(params.begin(), params.end(), [&key](auto& param) {
54-
return std::get<0>(param) == key;
55-
});
52+
auto entry = std::find_if(params.begin(), params.end(),
53+
[&key](auto& param) { return param.first == key; });
5654
return entry != params.end();
5755
}
5856

include/ada/url_search_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct url_search_params {
6868
std::string to_string();
6969

7070
private:
71-
std::vector<std::tuple<std::string, std::string>> params{};
71+
std::vector<std::pair<std::string, std::string>> params{};
7272
}; // url_search_params
7373

7474
} // namespace ada

src/url_search_params.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ namespace ada {
1111
void url_search_params::remove(const std::string_view key) {
1212
params.erase(
1313
std::remove_if(params.begin(), params.end(),
14-
[&key](auto &param) { return std::get<0>(param) == key; }),
14+
[&key](auto &param) { return param.first == key; }),
1515
params.end());
1616
}
1717

1818
void url_search_params::remove(const std::string_view key,
19-
std::string_view value) {
19+
const std::string_view value) {
2020
params.erase(std::remove_if(params.begin(), params.end(),
2121
[&key, &value](auto &param) {
22-
return std::get<0>(param) == key &&
23-
std::get<1>(param) == value;
22+
return param.first == key &&
23+
param.second == value;
2424
}),
2525
params.end());
2626
}
@@ -33,18 +33,16 @@ void url_search_params::set(const std::string_view key,
3333
const std::string_view value) {
3434
params.erase(
3535
std::remove_if(params.begin(), params.end(),
36-
[&key](auto &param) { return std::get<0>(param) == key; }),
36+
[&key](auto &param) { return param.first == key; }),
3737
params.end());
3838

39-
params.emplace_back(std::string(key), std::string(value));
39+
params.emplace_back(key, value);
4040
}
4141

4242
std::string url_search_params::to_string() {
4343
std::string out{};
4444
for (size_t i = 0; i < params.size(); i++) {
45-
auto param = params[i];
46-
auto key = std::get<0>(param);
47-
auto value = std::get<1>(param);
45+
auto [key, value] = params[i];
4846

4947
if (i != 0) {
5048
out += "&";

0 commit comments

Comments
 (0)