Skip to content

Commit ec4f790

Browse files
committed
Make constructors explicit and pass owning pointers by value
1 parent ef8f8ea commit ec4f790

File tree

135 files changed

+327
-314
lines changed

Some content is hidden

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

135 files changed

+327
-314
lines changed

include/graphqlservice/GraphQLResponse.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace graphql::response {
3333
// GraphQL responses are not technically JSON-specific, although that is probably the most common
3434
// way of representing them. These are the primitive types that may be represented in GraphQL, as
3535
// of the [October 2021 spec](https://spec.graphql.org/October2021/#sec-Serialization-Format).
36-
enum class [[nodiscard]] Type : std::uint8_t {
36+
enum class [[nodiscard]] Type : std::uint8_t
37+
{
3738
Map, // JSON Object
3839
List, // JSON Array
3940
String, // JSON String
@@ -392,7 +393,7 @@ class [[nodiscard]] Writer final
392393
template <class T>
393394
struct Model : Concept
394395
{
395-
Model(std::unique_ptr<T>&& pimpl)
396+
explicit Model(std::unique_ptr<T> pimpl) noexcept
396397
: _pimpl { std::move(pimpl) }
397398
{
398399
}
@@ -455,7 +456,7 @@ class [[nodiscard]] Writer final
455456

456457
public:
457458
template <class T>
458-
Writer(std::unique_ptr<T> writer)
459+
Writer(std::unique_ptr<T> writer) noexcept
459460
: _concept { std::static_pointer_cast<const Concept>(
460461
std::make_shared<Model<T>>(std::move(writer))) }
461462
{

include/graphqlservice/GraphQLService.h

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ constexpr std::string_view strSubscription { "subscription"sv };
134134
} // namespace keywords
135135

136136
// Resolvers may be called in multiple different Operation contexts.
137-
enum class [[nodiscard]] ResolverContext {
137+
enum class [[nodiscard]] ResolverContext
138+
{
138139
// Resolving a Query operation.
139140
Query,
140141

@@ -197,7 +198,7 @@ class [[nodiscard]] await_async final
197198
template <class T>
198199
struct [[nodiscard]] Model : Concept
199200
{
200-
Model(std::shared_ptr<T>&& pimpl)
201+
explicit Model(std::shared_ptr<T> pimpl) noexcept
201202
: _pimpl { std::move(pimpl) }
202203
{
203204
}
@@ -226,7 +227,7 @@ class [[nodiscard]] await_async final
226227
public:
227228
// Type-erased explicit constructor for a custom awaitable.
228229
template <class T>
229-
explicit await_async(std::shared_ptr<T> pimpl)
230+
explicit await_async(std::shared_ptr<T> pimpl) noexcept
230231
: _pimpl { std::make_shared<Model<T>>(std::move(pimpl)) }
231232
{
232233
}
@@ -586,7 +587,8 @@ using ResolverMap = internal::string_view_map<Resolver>;
586587
// GraphQL types are nullable by default, but they may be wrapped with non-null or list types.
587588
// Since nullability is a more special case in C++, we invert the default and apply that modifier
588589
// instead when the non-null wrapper is not present in that part of the wrapper chain.
589-
enum class [[nodiscard]] TypeModifier {
590+
enum class [[nodiscard]] TypeModifier
591+
{
590592
None,
591593
Nullable,
592594
List,
@@ -598,11 +600,13 @@ concept OnlyNoneModifiers = (... && (Other == TypeModifier::None));
598600

599601
// Test if the next modifier is Nullable.
600602
template <TypeModifier Modifier>
601-
concept NullableModifier = Modifier == TypeModifier::Nullable;
603+
concept NullableModifier = Modifier ==
604+
TypeModifier::Nullable;
602605

603606
// Test if the next modifier is List.
604607
template <TypeModifier Modifier>
605-
concept ListModifier = Modifier == TypeModifier::List;
608+
concept ListModifier = Modifier ==
609+
TypeModifier::List;
606610

607611
// Convert arguments and input types with a non-templated static method.
608612
template <typename Type>
@@ -634,12 +638,13 @@ namespace {
634638

635639
// These types are used as scalar arguments even though they are represented with a class.
636640
template <typename Type>
637-
concept ScalarArgumentClass = std::is_same_v<Type, std::string> || std::is_same_v<Type,
638-
response::IdType> || std::is_same_v<Type, response::Value>;
641+
concept ScalarArgumentClass = std::is_same_v<Type, std::string>
642+
|| std::is_same_v<Type, response::IdType> || std::is_same_v<Type, response::Value>;
639643

640644
// Any non-scalar class used in an argument is a generated INPUT_OBJECT type.
641645
template <typename Type>
642-
concept InputArgumentClass = std::is_class_v<Type> && !ScalarArgumentClass<Type>;
646+
concept InputArgumentClass = std::is_class_v<Type> && !
647+
ScalarArgumentClass<Type>;
643648

644649
// Special-case an innermost nullable INPUT_OBJECT type.
645650
template <typename Type, TypeModifier... Other>
@@ -710,8 +715,8 @@ struct ModifiedArgument
710715

711716
// Peel off the none modifier. If it's included, it should always be last in the list.
712717
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
713-
[[nodiscard]] static Type require(std::string_view name,
714-
const response::Value& arguments) requires OnlyNoneModifiers<Modifier, Other...>
718+
[[nodiscard]] static Type require(std::string_view name, const response::Value& arguments)
719+
requires OnlyNoneModifiers<Modifier, Other...>
715720
{
716721
static_assert(sizeof...(Other) == 0, "None modifier should always be last");
717722

@@ -722,7 +727,8 @@ struct ModifiedArgument
722727
// Peel off nullable modifiers.
723728
template <TypeModifier Modifier, TypeModifier... Other>
724729
[[nodiscard]] static typename ArgumentTraits<Type, Modifier, Other...>::type require(
725-
std::string_view name, const response::Value& arguments) requires NullableModifier<Modifier>
730+
std::string_view name, const response::Value& arguments)
731+
requires NullableModifier<Modifier>
726732
{
727733
const auto& valueItr = arguments.find(name);
728734

@@ -747,7 +753,8 @@ struct ModifiedArgument
747753
// Peel off list modifiers.
748754
template <TypeModifier Modifier, TypeModifier... Other>
749755
[[nodiscard]] static typename ArgumentTraits<Type, Modifier, Other...>::type require(
750-
std::string_view name, const response::Value& arguments) requires ListModifier<Modifier>
756+
std::string_view name, const response::Value& arguments)
757+
requires ListModifier<Modifier>
751758
{
752759
const auto& values = arguments[name];
753760
typename ArgumentTraits<Type, Modifier, Other...>::type result(values.size());
@@ -784,8 +791,8 @@ struct ModifiedArgument
784791

785792
// Peel off the none modifier. If it's included, it should always be last in the list.
786793
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
787-
[[nodiscard]] static Type duplicate(
788-
const Type& value) requires OnlyNoneModifiers<Modifier, Other...>
794+
[[nodiscard]] static Type duplicate(const Type& value)
795+
requires OnlyNoneModifiers<Modifier, Other...>
789796
{
790797
// Just copy the value.
791798
return Type { value };
@@ -794,8 +801,8 @@ struct ModifiedArgument
794801
// Peel off nullable modifiers.
795802
template <TypeModifier Modifier, TypeModifier... Other>
796803
[[nodiscard]] static typename ArgumentTraits<Type, Modifier, Other...>::type duplicate(
797-
const typename ArgumentTraits<Type, Modifier, Other...>::type& nullableValue) requires
798-
NullableModifier<Modifier>
804+
const typename ArgumentTraits<Type, Modifier, Other...>::type& nullableValue)
805+
requires NullableModifier<Modifier>
799806
{
800807
typename ArgumentTraits<Type, Modifier, Other...>::type result {};
801808

@@ -818,8 +825,8 @@ struct ModifiedArgument
818825
// Peel off list modifiers.
819826
template <TypeModifier Modifier, TypeModifier... Other>
820827
[[nodiscard]] static typename ArgumentTraits<Type, Modifier, Other...>::type duplicate(
821-
const typename ArgumentTraits<Type, Modifier, Other...>::type& listValue) requires
822-
ListModifier<Modifier>
828+
const typename ArgumentTraits<Type, Modifier, Other...>::type& listValue)
829+
requires ListModifier<Modifier>
823830
{
824831
typename ArgumentTraits<Type, Modifier, Other...>::type result(listValue.size());
825832

@@ -943,7 +950,8 @@ concept ObjectType = std::is_same_v<Object, Type>;
943950

944951
// Test if this Type inherits from Object but is not Object itself.
945952
template <typename Type>
946-
concept ObjectDerivedType = ObjectBaseType<Type> && !ObjectType<Type>;
953+
concept ObjectDerivedType = ObjectBaseType<Type> && !
954+
ObjectType<Type>;
947955

948956
// Test if a nullable type is std::shared_ptr<Type> or std::optional<T>.
949957
template <typename Type, TypeModifier... Other>
@@ -957,7 +965,8 @@ concept NoneObjectDerivedType = OnlyNoneModifiers<Modifier> && ObjectDerivedType
957965
// Test all other result types to see if they should call the specialized convert method without
958966
// template parameters.
959967
template <typename Type, TypeModifier Modifier>
960-
concept NoneScalarOrObjectType = OnlyNoneModifiers<Modifier> && !ObjectDerivedType<Type>;
968+
concept NoneScalarOrObjectType = OnlyNoneModifiers<Modifier> && !
969+
ObjectDerivedType<Type>;
961970

962971
// Test if this method should return a nullable std::shared_ptr<Type>
963972
template <typename Type, TypeModifier Modifier, TypeModifier... Other>
@@ -1001,8 +1010,8 @@ struct ModifiedResult
10011010
// Peel off the none modifier. If it's included, it should always be last in the list.
10021011
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
10031012
[[nodiscard]] static AwaitableResolver convert(
1004-
AwaitableObject<typename ResultTraits<Type>::type> result,
1005-
ResolverParams params) requires NoneObjectDerivedType<Type, Modifier>
1013+
AwaitableObject<typename ResultTraits<Type>::type> result, ResolverParams params)
1014+
requires NoneObjectDerivedType<Type, Modifier>
10061015
{
10071016
// Call through to the Object specialization with a static_pointer_cast for subclasses of
10081017
// Object.
@@ -1021,8 +1030,9 @@ struct ModifiedResult
10211030

10221031
// Peel off the none modifier. If it's included, it should always be last in the list.
10231032
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
1024-
[[nodiscard]] static AwaitableResolver convert(typename ResultTraits<Type>::future_type result,
1025-
ResolverParams params) requires NoneScalarOrObjectType<Type, Modifier>
1033+
[[nodiscard]] static AwaitableResolver convert(
1034+
typename ResultTraits<Type>::future_type result, ResolverParams params)
1035+
requires NoneScalarOrObjectType<Type, Modifier>
10261036
{
10271037
static_assert(sizeof...(Other) == 0, "None modifier should always be last");
10281038

@@ -1033,8 +1043,8 @@ struct ModifiedResult
10331043
// Peel off final nullable modifiers for std::shared_ptr of Object and subclasses of Object.
10341044
template <TypeModifier Modifier, TypeModifier... Other>
10351045
[[nodiscard]] static AwaitableResolver convert(
1036-
typename ResultTraits<Type, Modifier, Other...>::future_type result,
1037-
ResolverParams params) requires NullableResultSharedPtr<Type, Modifier, Other...>
1046+
typename ResultTraits<Type, Modifier, Other...>::future_type result, ResolverParams params)
1047+
requires NullableResultSharedPtr<Type, Modifier, Other...>
10381048
{
10391049
co_await params.launch;
10401050

@@ -1054,8 +1064,8 @@ struct ModifiedResult
10541064
// Peel off nullable modifiers for anything else, which should all be std::optional.
10551065
template <TypeModifier Modifier, TypeModifier... Other>
10561066
[[nodiscard]] static AwaitableResolver convert(
1057-
typename ResultTraits<Type, Modifier, Other...>::future_type result,
1058-
ResolverParams params) requires NullableResultOptional<Type, Modifier, Other...>
1067+
typename ResultTraits<Type, Modifier, Other...>::future_type result, ResolverParams params)
1068+
requires NullableResultOptional<Type, Modifier, Other...>
10591069
{
10601070
static_assert(std::is_same_v<std::optional<typename ResultTraits<Type, Other...>::type>,
10611071
typename ResultTraits<Type, Modifier, Other...>::type>,
@@ -1091,8 +1101,8 @@ struct ModifiedResult
10911101
// Peel off list modifiers.
10921102
template <TypeModifier Modifier, TypeModifier... Other>
10931103
[[nodiscard]] static AwaitableResolver convert(
1094-
typename ResultTraits<Type, Modifier, Other...>::future_type result,
1095-
ResolverParams params) requires ListModifier<Modifier>
1104+
typename ResultTraits<Type, Modifier, Other...>::future_type result, ResolverParams params)
1105+
requires ListModifier<Modifier>
10961106
{
10971107
if constexpr (!ObjectBaseType<Type>)
10981108
{
@@ -1192,8 +1202,8 @@ struct ModifiedResult
11921202

11931203
// Peel off the none modifier. If it's included, it should always be last in the list.
11941204
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
1195-
static void validateScalar(
1196-
const response::Value& value) requires OnlyNoneModifiers<Modifier, Other...>
1205+
static void validateScalar(const response::Value& value)
1206+
requires OnlyNoneModifiers<Modifier, Other...>
11971207
{
11981208
static_assert(sizeof...(Other) == 0, "None modifier should always be last");
11991209

@@ -1203,7 +1213,8 @@ struct ModifiedResult
12031213

12041214
// Peel off nullable modifiers.
12051215
template <TypeModifier Modifier, TypeModifier... Other>
1206-
static void validateScalar(const response::Value& value) requires NullableModifier<Modifier>
1216+
static void validateScalar(const response::Value& value)
1217+
requires NullableModifier<Modifier>
12071218
{
12081219
if (value.type() != response::Type::Null)
12091220
{
@@ -1213,7 +1224,8 @@ struct ModifiedResult
12131224

12141225
// Peel off list modifiers.
12151226
template <TypeModifier Modifier, TypeModifier... Other>
1216-
static void validateScalar(const response::Value& value) requires ListModifier<Modifier>
1227+
static void validateScalar(const response::Value& value)
1228+
requires ListModifier<Modifier>
12171229
{
12181230
if (value.type() != response::Type::List)
12191231
{

include/graphqlservice/introspection/DirectiveObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class [[nodiscard]] Directive final
3939
struct [[nodiscard]] Model
4040
: Concept
4141
{
42-
Model(std::shared_ptr<T>&& pimpl) noexcept
42+
explicit Model(std::shared_ptr<T> pimpl) noexcept
4343
: _pimpl { std::move(pimpl) }
4444
{
4545
}
@@ -79,7 +79,7 @@ class [[nodiscard]] Directive final
7979
[[nodiscard]] service::ResolverMap getResolvers() const noexcept;
8080

8181
public:
82-
GRAPHQLSERVICE_EXPORT Directive(std::shared_ptr<introspection::Directive> pimpl) noexcept;
82+
GRAPHQLSERVICE_EXPORT explicit Directive(std::shared_ptr<introspection::Directive> pimpl) noexcept;
8383
GRAPHQLSERVICE_EXPORT ~Directive();
8484
};
8585

include/graphqlservice/introspection/EnumValueObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class [[nodiscard]] EnumValue final
3737
struct [[nodiscard]] Model
3838
: Concept
3939
{
40-
Model(std::shared_ptr<T>&& pimpl) noexcept
40+
explicit Model(std::shared_ptr<T> pimpl) noexcept
4141
: _pimpl { std::move(pimpl) }
4242
{
4343
}
@@ -72,7 +72,7 @@ class [[nodiscard]] EnumValue final
7272
[[nodiscard]] service::ResolverMap getResolvers() const noexcept;
7373

7474
public:
75-
GRAPHQLSERVICE_EXPORT EnumValue(std::shared_ptr<introspection::EnumValue> pimpl) noexcept;
75+
GRAPHQLSERVICE_EXPORT explicit EnumValue(std::shared_ptr<introspection::EnumValue> pimpl) noexcept;
7676
GRAPHQLSERVICE_EXPORT ~EnumValue();
7777
};
7878

include/graphqlservice/introspection/FieldObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class [[nodiscard]] Field final
4141
struct [[nodiscard]] Model
4242
: Concept
4343
{
44-
Model(std::shared_ptr<T>&& pimpl) noexcept
44+
explicit Model(std::shared_ptr<T> pimpl) noexcept
4545
: _pimpl { std::move(pimpl) }
4646
{
4747
}
@@ -86,7 +86,7 @@ class [[nodiscard]] Field final
8686
[[nodiscard]] service::ResolverMap getResolvers() const noexcept;
8787

8888
public:
89-
GRAPHQLSERVICE_EXPORT Field(std::shared_ptr<introspection::Field> pimpl) noexcept;
89+
GRAPHQLSERVICE_EXPORT explicit Field(std::shared_ptr<introspection::Field> pimpl) noexcept;
9090
GRAPHQLSERVICE_EXPORT ~Field();
9191
};
9292

include/graphqlservice/introspection/InputValueObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class [[nodiscard]] InputValue final
3737
struct [[nodiscard]] Model
3838
: Concept
3939
{
40-
Model(std::shared_ptr<T>&& pimpl) noexcept
40+
explicit Model(std::shared_ptr<T> pimpl) noexcept
4141
: _pimpl { std::move(pimpl) }
4242
{
4343
}
@@ -72,7 +72,7 @@ class [[nodiscard]] InputValue final
7272
[[nodiscard]] service::ResolverMap getResolvers() const noexcept;
7373

7474
public:
75-
GRAPHQLSERVICE_EXPORT InputValue(std::shared_ptr<introspection::InputValue> pimpl) noexcept;
75+
GRAPHQLSERVICE_EXPORT explicit InputValue(std::shared_ptr<introspection::InputValue> pimpl) noexcept;
7676
GRAPHQLSERVICE_EXPORT ~InputValue();
7777
};
7878

include/graphqlservice/introspection/SchemaObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class [[nodiscard]] Schema final
4141
struct [[nodiscard]] Model
4242
: Concept
4343
{
44-
Model(std::shared_ptr<T>&& pimpl) noexcept
44+
explicit Model(std::shared_ptr<T> pimpl) noexcept
4545
: _pimpl { std::move(pimpl) }
4646
{
4747
}
@@ -86,7 +86,7 @@ class [[nodiscard]] Schema final
8686
[[nodiscard]] service::ResolverMap getResolvers() const noexcept;
8787

8888
public:
89-
GRAPHQLSERVICE_EXPORT Schema(std::shared_ptr<introspection::Schema> pimpl) noexcept;
89+
GRAPHQLSERVICE_EXPORT explicit Schema(std::shared_ptr<introspection::Schema> pimpl) noexcept;
9090
GRAPHQLSERVICE_EXPORT ~Schema();
9191
};
9292

include/graphqlservice/introspection/TypeObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class [[nodiscard]] Type final
4949
struct [[nodiscard]] Model
5050
: Concept
5151
{
52-
Model(std::shared_ptr<T>&& pimpl) noexcept
52+
explicit Model(std::shared_ptr<T> pimpl) noexcept
5353
: _pimpl { std::move(pimpl) }
5454
{
5555
}
@@ -114,7 +114,7 @@ class [[nodiscard]] Type final
114114
[[nodiscard]] service::ResolverMap getResolvers() const noexcept;
115115

116116
public:
117-
GRAPHQLSERVICE_EXPORT Type(std::shared_ptr<introspection::Type> pimpl) noexcept;
117+
GRAPHQLSERVICE_EXPORT explicit Type(std::shared_ptr<introspection::Type> pimpl) noexcept;
118118
GRAPHQLSERVICE_EXPORT ~Type();
119119
};
120120

samples/learn/schema/CharacterObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using namespace std::literals;
1414
namespace graphql::learn {
1515
namespace object {
1616

17-
Character::Character(std::unique_ptr<const Concept>&& pimpl) noexcept
17+
Character::Character(std::unique_ptr<const Concept> pimpl) noexcept
1818
: service::Object { pimpl->getTypeNames(), pimpl->getResolvers() }
1919
, _pimpl { std::move(pimpl) }
2020
{

0 commit comments

Comments
 (0)