Skip to content

Commit 8eb93c4

Browse files
authored
Merge pull request #315 from wravery/next
minor std::format fixes
2 parents e1636d2 + 79af047 commit 8eb93c4

File tree

90 files changed

+556
-853
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+556
-853
lines changed

cmake/cppgraphqlgen-functions.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function(add_graphql_schema_target SCHEMA_TARGET)
5353
target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET HEADERS
5454
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
5555
FILES ${SCHEMA_HEADERS})
56-
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlservice GRAPHQL_BUILD_MODULES)
56+
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlservice INTERFACE_CXX_MODULE_SETS)
5757
if(GRAPHQL_BUILD_MODULES)
5858
file(GLOB SCHEMA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx)
5959
target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET CXX_MODULES
@@ -107,7 +107,7 @@ function(add_graphql_client_target CLIENT_TARGET)
107107
target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET HEADERS
108108
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
109109
FILES ${CLIENT_HEADERS})
110-
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlclient GRAPHQL_BUILD_MODULES)
110+
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlclient INTERFACE_CXX_MODULE_SETS)
111111
if(GRAPHQL_BUILD_MODULES)
112112
file(GLOB CLIENT_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx)
113113
target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET CXX_MODULES

include/graphqlservice/GraphQLClient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <algorithm>
1414
#include <iterator>
1515
#include <optional>
16+
#include <ranges>
1617
#include <stdexcept>
1718
#include <vector>
1819

@@ -167,7 +168,7 @@ struct ModifiedVariable
167168
response::Value result { response::Type::List };
168169

169170
result.reserve(listValue.size());
170-
std::for_each(listValue.begin(), listValue.end(), [&result](auto& value) {
171+
std::ranges::for_each(listValue, [&result](auto& value) {
171172
result.emplace_back(serialize<Other...>(std::move(value)));
172173
});
173174
listValue.clear();
@@ -218,7 +219,7 @@ struct ModifiedVariable
218219
{
219220
typename VariableTraits<Type, Modifier, Other...>::type result(listValue.size());
220221

221-
std::transform(listValue.cbegin(), listValue.cend(), result.begin(), duplicate<Other...>);
222+
std::ranges::transform(listValue, result.begin(), duplicate<Other...>);
222223

223224
return result;
224225
}
@@ -322,8 +323,7 @@ struct ModifiedResponse
322323
auto listValue = response.release<response::ListType>();
323324

324325
result.reserve(listValue.size());
325-
std::transform(listValue.begin(),
326-
listValue.end(),
326+
std::ranges::transform(listValue,
327327
std::back_inserter(result),
328328
[](response::Value& value) {
329329
return parse<Other...>(std::move(value));

include/graphqlservice/GraphQLService.h

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
#include <chrono>
1717
#include <condition_variable>
1818
#include <coroutine>
19+
#include <format>
1920
#include <future>
2021
#include <list>
2122
#include <map>
2223
#include <memory>
2324
#include <mutex>
2425
#include <optional>
25-
#include <sstream>
26+
#include <ranges>
2627
#include <stdexcept>
2728
#include <string>
2829
#include <thread>
@@ -685,11 +686,7 @@ struct ModifiedArgument
685686

686687
for (auto& error : errors)
687688
{
688-
std::ostringstream message;
689-
690-
message << "Invalid argument: " << name << " error: " << error.message;
691-
692-
error.message = message.str();
689+
error.message = std::format("Invalid argument: {} error: {}", name, error.message);
693690
}
694691

695692
throw schema_exception(std::move(errors));
@@ -758,8 +755,8 @@ struct ModifiedArgument
758755
typename ArgumentTraits<Type, Modifier, Other...>::type result(values.size());
759756
const auto& elements = values.get<response::ListType>();
760757

761-
std::transform(elements.cbegin(),
762-
elements.cend(),
758+
std::transform(elements.begin(),
759+
elements.end(),
763760
result.begin(),
764761
[name](const response::Value& element) {
765762
response::Value single(response::Type::Map);
@@ -831,7 +828,7 @@ struct ModifiedArgument
831828
{
832829
typename ArgumentTraits<Type, Modifier, Other...>::type result(listValue.size());
833830

834-
std::transform(listValue.cbegin(), listValue.cend(), result.begin(), duplicate<Other...>);
831+
std::ranges::transform(listValue, result.begin(), duplicate<Other...>);
835832

836833
return result;
837834
}
@@ -1200,12 +1197,11 @@ struct ModifiedResult
12001197
}
12011198
catch (const std::exception& ex)
12021199
{
1203-
std::ostringstream message;
1200+
auto message = std::format("Field error name: {} unknown error: {}",
1201+
params.fieldName,
1202+
ex.what());
12041203

1205-
message << "Field error name: " << params.fieldName
1206-
<< " unknown error: " << ex.what();
1207-
1208-
document.errors.emplace_back(schema_error { message.str(),
1204+
document.errors.emplace_back(schema_error { std::move(message),
12091205
params.getLocation(),
12101206
buildErrorPath(params.errorPath) });
12111207
}
@@ -1293,11 +1289,10 @@ struct ModifiedResult
12931289
}
12941290
catch (const std::exception& ex)
12951291
{
1296-
std::ostringstream message;
1297-
1298-
message << "Field name: " << params.fieldName << " unknown error: " << ex.what();
1292+
auto message =
1293+
std::format("Field name: {} unknown error: {}", params.fieldName, ex.what());
12991294

1300-
document.errors.emplace_back(schema_error { message.str(),
1295+
document.errors.emplace_back(schema_error { std::move(message),
13011296
params.getLocation(),
13021297
buildErrorPath(params.errorPath) });
13031298
}

samples/client/benchmark.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88
#include <iterator>
99
#include <numeric>
10+
#include <ranges>
1011
#include <stdexcept>
1112
#include <string>
1213
#include <string_view>
@@ -45,7 +46,7 @@ void outputOverview(
4546
void outputSegment(
4647
std::string_view name, std::vector<std::chrono::steady_clock::duration>& durations) noexcept
4748
{
48-
std::sort(durations.begin(), durations.end());
49+
std::ranges::sort(durations);
4950

5051
const auto count = durations.size();
5152
const auto total =

samples/client/benchmark/BenchmarkClient.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111
#include <array>
1212
#include <cstddef>
13-
#include <sstream>
1413
#include <stdexcept>
1514
#include <string_view>
1615
#include <utility>

samples/client/multiple/MultipleQueriesClient.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111
#include <array>
1212
#include <cstddef>
13-
#include <sstream>
1413
#include <stdexcept>
1514
#include <string_view>
1615
#include <utility>

samples/client/mutate/MutateClient.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111
#include <array>
1212
#include <cstddef>
13-
#include <sstream>
1413
#include <stdexcept>
1514
#include <string_view>
1615
#include <utility>

samples/client/nestedinput/NestedInputClient.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111
#include <array>
1212
#include <cstddef>
13-
#include <sstream>
1413
#include <stdexcept>
1514
#include <string_view>
1615
#include <utility>

samples/client/query/QueryClient.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111
#include <array>
1212
#include <cstddef>
13-
#include <sstream>
1413
#include <stdexcept>
1514
#include <string_view>
1615
#include <utility>

samples/client/subscribe/SubscribeClient.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111
#include <array>
1212
#include <cstddef>
13-
#include <sstream>
1413
#include <stdexcept>
1514
#include <string_view>
1615
#include <utility>

samples/learn/DroidData.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ void Droid::addFriends(
2121
{
2222
friends_.resize(friends.size());
2323

24-
std::transform(friends.begin(),
25-
friends.end(),
26-
friends_.begin(),
27-
[](const auto& spFriend) noexcept {
28-
return std::visit(
29-
[](const auto& hero) noexcept {
30-
return WeakHero {
31-
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
32-
};
33-
},
34-
spFriend);
35-
});
24+
std::ranges::transform(friends, friends_.begin(), [](const auto& spFriend) noexcept {
25+
return std::visit(
26+
[](const auto& hero) noexcept {
27+
return WeakHero {
28+
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
29+
};
30+
},
31+
spFriend);
32+
});
3633
}
3734

3835
const response::IdType& Droid::getId() const noexcept
@@ -49,12 +46,9 @@ std::optional<std::vector<std::shared_ptr<object::Character>>> Droid::getFriends
4946
{
5047
std::vector<std::shared_ptr<object::Character>> result(friends_.size());
5148

52-
std::transform(friends_.begin(),
53-
friends_.end(),
54-
result.begin(),
55-
[](const auto& wpFriend) noexcept {
56-
return make_hero(wpFriend);
57-
});
49+
std::ranges::transform(friends_, result.begin(), [](const auto& wpFriend) noexcept {
50+
return make_hero(wpFriend);
51+
});
5852
result.erase(std::remove(result.begin(), result.end(), std::shared_ptr<object::Character> {}),
5953
result.end());
6054

@@ -65,12 +59,9 @@ std::optional<std::vector<std::optional<Episode>>> Droid::getAppearsIn() const n
6559
{
6660
std::vector<std::optional<Episode>> result(appearsIn_.size());
6761

68-
std::transform(appearsIn_.begin(),
69-
appearsIn_.end(),
70-
result.begin(),
71-
[](const auto& entry) noexcept {
72-
return std::make_optional(entry);
73-
});
62+
std::ranges::transform(appearsIn_, result.begin(), [](const auto& entry) noexcept {
63+
return std::make_optional(entry);
64+
});
7465

7566
return result.empty() ? std::nullopt : std::make_optional(std::move(result));
7667
}

samples/learn/HumanData.cpp

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ void Human::addFriends(std::vector<SharedHero> friends) noexcept
2020
{
2121
friends_.resize(friends.size());
2222

23-
std::transform(friends.begin(),
24-
friends.end(),
25-
friends_.begin(),
26-
[](const auto& spFriend) noexcept {
27-
return std::visit(
28-
[](const auto& hero) noexcept {
29-
return WeakHero {
30-
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
31-
};
32-
},
33-
spFriend);
34-
});
23+
std::ranges::transform(friends, friends_.begin(), [](const auto& spFriend) noexcept {
24+
return std::visit(
25+
[](const auto& hero) noexcept {
26+
return WeakHero {
27+
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
28+
};
29+
},
30+
spFriend);
31+
});
3532
}
3633

3734
const response::IdType& Human::getId() const noexcept
@@ -48,12 +45,9 @@ std::optional<std::vector<std::shared_ptr<object::Character>>> Human::getFriends
4845
{
4946
std::vector<std::shared_ptr<object::Character>> result(friends_.size());
5047

51-
std::transform(friends_.begin(),
52-
friends_.end(),
53-
result.begin(),
54-
[](const auto& wpFriend) noexcept {
55-
return make_hero(wpFriend);
56-
});
48+
std::ranges::transform(friends_, result.begin(), [](const auto& wpFriend) noexcept {
49+
return make_hero(wpFriend);
50+
});
5751
result.erase(std::remove(result.begin(), result.end(), std::shared_ptr<object::Character> {}),
5852
result.end());
5953

@@ -64,12 +58,9 @@ std::optional<std::vector<std::optional<Episode>>> Human::getAppearsIn() const n
6458
{
6559
std::vector<std::optional<Episode>> result(appearsIn_.size());
6660

67-
std::transform(appearsIn_.begin(),
68-
appearsIn_.end(),
69-
result.begin(),
70-
[](const auto& entry) noexcept {
71-
return std::make_optional(entry);
72-
});
61+
std::ranges::transform(appearsIn_, result.begin(), [](const auto& entry) noexcept {
62+
return std::make_optional(entry);
63+
});
7364

7465
return result.empty() ? std::nullopt : std::make_optional(std::move(result));
7566
}

samples/learn/schema/DroidObject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <algorithm>
1414
#include <functional>
15-
#include <sstream>
1615
#include <stdexcept>
1716
#include <unordered_map>
1817

samples/learn/schema/HumanObject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <algorithm>
1414
#include <functional>
15-
#include <sstream>
1615
#include <stdexcept>
1716
#include <unordered_map>
1817

samples/learn/schema/MutationObject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <algorithm>
1414
#include <functional>
15-
#include <sstream>
1615
#include <stdexcept>
1716
#include <unordered_map>
1817

samples/learn/schema/QueryObject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <algorithm>
1717
#include <functional>
18-
#include <sstream>
1918
#include <stdexcept>
2019
#include <unordered_map>
2120

samples/learn/schema/ReviewObject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <algorithm>
1313
#include <functional>
14-
#include <sstream>
1514
#include <stdexcept>
1615
#include <unordered_map>
1716

samples/learn/schema/StarWarsSchema.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <array>
1515
#include <cstddef>
1616
#include <functional>
17-
#include <sstream>
1817
#include <stdexcept>
1918
#include <string_view>
2019
#include <utility>

samples/proxy/query/ProxyClient.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <algorithm>
1111
#include <array>
1212
#include <cstddef>
13-
#include <sstream>
1413
#include <stdexcept>
1514
#include <string_view>
1615
#include <utility>

samples/proxy/schema/ProxySchema.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <array>
1414
#include <cstddef>
1515
#include <functional>
16-
#include <sstream>
1716
#include <stdexcept>
1817
#include <string_view>
1918
#include <utility>

samples/proxy/schema/QueryObject.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include <algorithm>
1414
#include <functional>
15-
#include <sstream>
1615
#include <stdexcept>
1716
#include <unordered_map>
1817

0 commit comments

Comments
 (0)