Skip to content

Commit b494316

Browse files
committed
Fix new warnings in GCC 12
1 parent 692a048 commit b494316

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

include/graphqlservice/internal/SortedMap.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ struct [[nodiscard]] sorted_map_key
2323
{
2424
}
2525

26-
constexpr sorted_map_key(const K& key) noexcept
26+
constexpr sorted_map_key(K key) noexcept
2727
: key { key }
2828
{
2929
}
3030

3131
constexpr ~sorted_map_key() noexcept = default;
3232

33-
const K& key;
33+
K key;
3434
};
3535

3636
template <class Compare, class Iterator, class K,
3737
class V = decltype(std::declval<Iterator>()->second)>
3838
[[nodiscard]] constexpr std::pair<Iterator, Iterator> sorted_map_equal_range(
39-
Iterator itrBegin, Iterator itrEnd, const K& key) noexcept
39+
Iterator itrBegin, Iterator itrEnd, K key) noexcept
4040
{
4141
return std::equal_range(itrBegin,
4242
itrEnd,
@@ -47,7 +47,7 @@ template <class Compare, class Iterator, class K,
4747
}
4848

4949
template <class Compare, class Container, class K>
50-
[[nodiscard]] constexpr auto sorted_map_lookup(const Container& container, const K& key) noexcept
50+
[[nodiscard]] constexpr auto sorted_map_lookup(const Container& container, K key) noexcept
5151
{
5252
const auto [itr, itrEnd] =
5353
sorted_map_equal_range<Compare>(container.begin(), container.end(), key);
@@ -131,7 +131,7 @@ class [[nodiscard]] sorted_map
131131
return _data.rend();
132132
}
133133

134-
[[nodiscard]] constexpr const_iterator find(const K& key) const noexcept
134+
[[nodiscard]] constexpr const_iterator find(K key) const noexcept
135135
{
136136
const auto [itr, itrEnd] = sorted_map_equal_range<Compare>(_data.begin(), _data.end(), key);
137137

@@ -161,7 +161,7 @@ class [[nodiscard]] sorted_map
161161
true };
162162
}
163163

164-
inline const_iterator erase(const K& key) noexcept
164+
inline const_iterator erase(K key) noexcept
165165
{
166166
const auto [itr, itrEnd] = sorted_map_equal_range<Compare>(_data.begin(), _data.end(), key);
167167

@@ -291,12 +291,11 @@ class [[nodiscard]] sorted_set
291291
return _data.rend();
292292
}
293293

294-
[[nodiscard]] constexpr const_iterator find(const K& key) const noexcept
294+
[[nodiscard]] constexpr const_iterator find(K key) const noexcept
295295
{
296-
const auto [itr, itrEnd] =
297-
std::equal_range(begin(), end(), key, [](const K& lhs, const K& rhs) noexcept {
298-
return Compare {}(lhs, rhs);
299-
});
296+
const auto [itr, itrEnd] = std::equal_range(begin(), end(), key, [](K lhs, K rhs) noexcept {
297+
return Compare {}(lhs, rhs);
298+
});
300299

301300
return itr == itrEnd ? _data.end() : itr;
302301
}
@@ -312,10 +311,8 @@ class [[nodiscard]] sorted_set
312311
template <typename Arg>
313312
inline std::pair<const_iterator, bool> emplace(Arg&& key) noexcept
314313
{
315-
const auto [itr, itrEnd] = std::equal_range(_data.begin(),
316-
_data.end(),
317-
key,
318-
[](const auto& lhs, const auto& rhs) noexcept {
314+
const auto [itr, itrEnd] =
315+
std::equal_range(_data.begin(), _data.end(), key, [](K lhs, K rhs) noexcept {
319316
return Compare {}(lhs, rhs);
320317
});
321318

@@ -327,12 +324,10 @@ class [[nodiscard]] sorted_set
327324
return { _data.emplace(itrEnd, std::forward<Arg>(key)), true };
328325
}
329326

330-
inline const_iterator erase(const K& key) noexcept
327+
inline const_iterator erase(K key) noexcept
331328
{
332-
const auto [itr, itrEnd] = std::equal_range(_data.begin(),
333-
_data.end(),
334-
key,
335-
[](const K& lhs, const K& rhs) noexcept {
329+
const auto [itr, itrEnd] =
330+
std::equal_range(_data.begin(), _data.end(), key, [](K lhs, K rhs) noexcept {
336331
return Compare {}(lhs, rhs);
337332
});
338333

@@ -364,7 +359,7 @@ class [[nodiscard]] sorted_set
364359
struct [[nodiscard]] shorter_or_less
365360
{
366361
[[nodiscard]] constexpr bool operator()(
367-
const std::string_view& lhs, const std::string_view& rhs) const noexcept
362+
std::string_view lhs, std::string_view rhs) const noexcept
368363
{
369364
return lhs.size() == rhs.size() ? lhs < rhs : lhs.size() < rhs.size();
370365
}

samples/today/TodayMock.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace graphql::today {
2222
const response::IdType& getFakeAppointmentId() noexcept
2323
{
2424
static const auto s_fakeId = []() noexcept {
25-
std::string fakeIdString("fakeAppointmentId");
25+
std::string_view fakeIdString { "fakeAppointmentId" };
2626
response::IdType result(fakeIdString.size());
2727

2828
std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin());
@@ -36,7 +36,7 @@ const response::IdType& getFakeAppointmentId() noexcept
3636
const response::IdType& getFakeTaskId() noexcept
3737
{
3838
static const auto s_fakeId = []() noexcept {
39-
std::string fakeIdString("fakeTaskId");
39+
std::string_view fakeIdString { "fakeTaskId" };
4040
response::IdType result(fakeIdString.size());
4141

4242
std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin());
@@ -50,7 +50,7 @@ const response::IdType& getFakeTaskId() noexcept
5050
const response::IdType& getFakeFolderId() noexcept
5151
{
5252
static const auto s_fakeId = []() noexcept {
53-
std::string fakeIdString("fakeFolderId");
53+
std::string_view fakeIdString { "fakeFolderId" };
5454
response::IdType result(fakeIdString.size());
5555

5656
std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin());

test/ResponseTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TEST(ResponseCase, ValueConstructorFromStringLiteral)
1919
TEST(ResponseCase, IdTypeCompareEqual)
2020
{
2121
const auto fakeId = []() noexcept {
22-
std::string fakeIdString("fakeId");
22+
std::string_view fakeIdString { "fakeId" };
2323
response::IdType result(fakeIdString.size());
2424

2525
std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin());

0 commit comments

Comments
 (0)