Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor std::format fixes #315

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/cppgraphqlgen-functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function(add_graphql_schema_target SCHEMA_TARGET)
target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${SCHEMA_HEADERS})
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlservice GRAPHQL_BUILD_MODULES)
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlservice INTERFACE_CXX_MODULE_SETS)
if(GRAPHQL_BUILD_MODULES)
file(GLOB SCHEMA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx)
target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET CXX_MODULES
Expand Down Expand Up @@ -107,7 +107,7 @@ function(add_graphql_client_target CLIENT_TARGET)
target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${CLIENT_HEADERS})
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlclient GRAPHQL_BUILD_MODULES)
get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlclient INTERFACE_CXX_MODULE_SETS)
if(GRAPHQL_BUILD_MODULES)
file(GLOB CLIENT_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx)
target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET CXX_MODULES
Expand Down
8 changes: 4 additions & 4 deletions include/graphqlservice/GraphQLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <algorithm>
#include <iterator>
#include <optional>
#include <ranges>
#include <stdexcept>
#include <vector>

Expand Down Expand Up @@ -167,7 +168,7 @@ struct ModifiedVariable
response::Value result { response::Type::List };

result.reserve(listValue.size());
std::for_each(listValue.begin(), listValue.end(), [&result](auto& value) {
std::ranges::for_each(listValue, [&result](auto& value) {
result.emplace_back(serialize<Other...>(std::move(value)));
});
listValue.clear();
Expand Down Expand Up @@ -218,7 +219,7 @@ struct ModifiedVariable
{
typename VariableTraits<Type, Modifier, Other...>::type result(listValue.size());

std::transform(listValue.cbegin(), listValue.cend(), result.begin(), duplicate<Other...>);
std::ranges::transform(listValue, result.begin(), duplicate<Other...>);

return result;
}
Expand Down Expand Up @@ -322,8 +323,7 @@ struct ModifiedResponse
auto listValue = response.release<response::ListType>();

result.reserve(listValue.size());
std::transform(listValue.begin(),
listValue.end(),
std::ranges::transform(listValue,
std::back_inserter(result),
[](response::Value& value) {
return parse<Other...>(std::move(value));
Expand Down
31 changes: 13 additions & 18 deletions include/graphqlservice/GraphQLService.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
#include <chrono>
#include <condition_variable>
#include <coroutine>
#include <format>
#include <future>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <optional>
#include <sstream>
#include <ranges>
#include <stdexcept>
#include <string>
#include <thread>
Expand Down Expand Up @@ -685,11 +686,7 @@ struct ModifiedArgument

for (auto& error : errors)
{
std::ostringstream message;

message << "Invalid argument: " << name << " error: " << error.message;

error.message = message.str();
error.message = std::format("Invalid argument: {} error: {}", name, error.message);
}

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

std::transform(elements.cbegin(),
elements.cend(),
std::transform(elements.begin(),
elements.end(),
result.begin(),
[name](const response::Value& element) {
response::Value single(response::Type::Map);
Expand Down Expand Up @@ -831,7 +828,7 @@ struct ModifiedArgument
{
typename ArgumentTraits<Type, Modifier, Other...>::type result(listValue.size());

std::transform(listValue.cbegin(), listValue.cend(), result.begin(), duplicate<Other...>);
std::ranges::transform(listValue, result.begin(), duplicate<Other...>);

return result;
}
Expand Down Expand Up @@ -1200,12 +1197,11 @@ struct ModifiedResult
}
catch (const std::exception& ex)
{
std::ostringstream message;
auto message = std::format("Field error name: {} unknown error: {}",
params.fieldName,
ex.what());

message << "Field error name: " << params.fieldName
<< " unknown error: " << ex.what();

document.errors.emplace_back(schema_error { message.str(),
document.errors.emplace_back(schema_error { std::move(message),
params.getLocation(),
buildErrorPath(params.errorPath) });
}
Expand Down Expand Up @@ -1293,11 +1289,10 @@ struct ModifiedResult
}
catch (const std::exception& ex)
{
std::ostringstream message;

message << "Field name: " << params.fieldName << " unknown error: " << ex.what();
auto message =
std::format("Field name: {} unknown error: {}", params.fieldName, ex.what());

document.errors.emplace_back(schema_error { message.str(),
document.errors.emplace_back(schema_error { std::move(message),
params.getLocation(),
buildErrorPath(params.errorPath) });
}
Expand Down
3 changes: 2 additions & 1 deletion samples/client/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <iostream>
#include <iterator>
#include <numeric>
#include <ranges>
#include <stdexcept>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -45,7 +46,7 @@ void outputOverview(
void outputSegment(
std::string_view name, std::vector<std::chrono::steady_clock::duration>& durations) noexcept
{
std::sort(durations.begin(), durations.end());
std::ranges::sort(durations);

const auto count = durations.size();
const auto total =
Expand Down
1 change: 0 additions & 1 deletion samples/client/benchmark/BenchmarkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/client/multiple/MultipleQueriesClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/client/mutate/MutateClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/client/nestedinput/NestedInputClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/client/query/QueryClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/client/subscribe/SubscribeClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
39 changes: 15 additions & 24 deletions samples/learn/DroidData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ void Droid::addFriends(
{
friends_.resize(friends.size());

std::transform(friends.begin(),
friends.end(),
friends_.begin(),
[](const auto& spFriend) noexcept {
return std::visit(
[](const auto& hero) noexcept {
return WeakHero {
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
};
},
spFriend);
});
std::ranges::transform(friends, friends_.begin(), [](const auto& spFriend) noexcept {
return std::visit(
[](const auto& hero) noexcept {
return WeakHero {
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
};
},
spFriend);
});
}

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

std::transform(friends_.begin(),
friends_.end(),
result.begin(),
[](const auto& wpFriend) noexcept {
return make_hero(wpFriend);
});
std::ranges::transform(friends_, result.begin(), [](const auto& wpFriend) noexcept {
return make_hero(wpFriend);
});
result.erase(std::remove(result.begin(), result.end(), std::shared_ptr<object::Character> {}),
result.end());

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

std::transform(appearsIn_.begin(),
appearsIn_.end(),
result.begin(),
[](const auto& entry) noexcept {
return std::make_optional(entry);
});
std::ranges::transform(appearsIn_, result.begin(), [](const auto& entry) noexcept {
return std::make_optional(entry);
});

return result.empty() ? std::nullopt : std::make_optional(std::move(result));
}
Expand Down
39 changes: 15 additions & 24 deletions samples/learn/HumanData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@ void Human::addFriends(std::vector<SharedHero> friends) noexcept
{
friends_.resize(friends.size());

std::transform(friends.begin(),
friends.end(),
friends_.begin(),
[](const auto& spFriend) noexcept {
return std::visit(
[](const auto& hero) noexcept {
return WeakHero {
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
};
},
spFriend);
});
std::ranges::transform(friends, friends_.begin(), [](const auto& spFriend) noexcept {
return std::visit(
[](const auto& hero) noexcept {
return WeakHero {
std::weak_ptr<typename std::decay_t<decltype(hero)>::element_type> { hero }
};
},
spFriend);
});
}

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

std::transform(friends_.begin(),
friends_.end(),
result.begin(),
[](const auto& wpFriend) noexcept {
return make_hero(wpFriend);
});
std::ranges::transform(friends_, result.begin(), [](const auto& wpFriend) noexcept {
return make_hero(wpFriend);
});
result.erase(std::remove(result.begin(), result.end(), std::shared_ptr<object::Character> {}),
result.end());

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

std::transform(appearsIn_.begin(),
appearsIn_.end(),
result.begin(),
[](const auto& entry) noexcept {
return std::make_optional(entry);
});
std::ranges::transform(appearsIn_, result.begin(), [](const auto& entry) noexcept {
return std::make_optional(entry);
});

return result.empty() ? std::nullopt : std::make_optional(std::move(result));
}
Expand Down
1 change: 0 additions & 1 deletion samples/learn/schema/DroidObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <algorithm>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>

Expand Down
1 change: 0 additions & 1 deletion samples/learn/schema/HumanObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <algorithm>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>

Expand Down
1 change: 0 additions & 1 deletion samples/learn/schema/MutationObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <algorithm>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>

Expand Down
1 change: 0 additions & 1 deletion samples/learn/schema/QueryObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <algorithm>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>

Expand Down
1 change: 0 additions & 1 deletion samples/learn/schema/ReviewObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <algorithm>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>

Expand Down
1 change: 0 additions & 1 deletion samples/learn/schema/StarWarsSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <array>
#include <cstddef>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/proxy/query/ProxyClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <array>
#include <cstddef>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/proxy/schema/ProxySchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <array>
#include <cstddef>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <string_view>
#include <utility>
Expand Down
1 change: 0 additions & 1 deletion samples/proxy/schema/QueryObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <algorithm>
#include <functional>
#include <sstream>
#include <stdexcept>
#include <unordered_map>

Expand Down
Loading