Tag: c#
-
HotChocolate UseSorting doesn’t work on computed fields
0 I have an ItemType defined with some custom fields that are resolved with ResolveWith: public class ItemType : ObjectType<Item> { protected override void Configure(IObjectTypeDescriptor<FilterTreeItem> descriptor) { descriptor .Field(“fullName”) .Type<StringType>() .ResolveWith<Resolver>(r => r.GetFullName(default!)); // Other properties } private class Resolver { public async Task<string> GetFullName([Parent] Item? parent, CancellationToken cancellationToken = default) { return quot;{parent.FirstName} {parent.LastName}”;…
-
hotchocolate schema stitching with another language server
1 I have a question for a custom scalar converter and schema stitching. I want to stitch a schema from a third party Server and from my own server. But the other server uses Java and a "BigDecimal" Type. And when I load the schema in "banana cake pop" or any other UI tool (postman,…
-
Does the definition int a = 0, b = a++, c = a++; have defined behavior in C?
19 Does the definition int a = 0, b = a++, c = a++; have defined behavior in C? Or almost equivalently, does the , in an object definition introduce a sequence point as for the comma operator in expressions? Similar questions have been asked for C++: Does `int a = 0, b = a`…
-
Convenient way to declare 2D (or even higher dimension) arrays with std::array
26 I’m about to convert a lot of old C++ code to more modern C++. There are many raw 2D arrays in that code like: Foo bar[XSIZE][YSIZE]; And I’m about to replace these declarations with std::array<std::array<Foo, YSIZE>, XSIZE> bar; This is a convenient way because the statements stay the same and the code is supposed…
-
How can I get a warning when comparing unsigned integers of different size in C and C++?
27 A common source of bugs in C or C++ is code like size_t n = // … for (unsigned int i = 0; i < n; i++) // … which can infinite-loop when the unsigned int overflows. For example, on Linux, unsigned int is 32-bit, while size_t is 64-bit, so if n = 5000000000,…
-
How to get a warning when comparing unsigned integers of different size in C and C++?
18 A common source of bugs in C or C++ is code like size_t n = // … for (unsigned int i = 0; i < n; i++) // … which can infinite-loop when the unsigned int overflows. For example on Linux unsigned int is 32-bit, while size_t is 64-bit, so if n = 5000000000,…
-
Lambda passed by reference runs when invoked in the constructor, but not when later stored in a data member
27 The following C++ code prints 11.1 then crashes. The lambda function seems to be called correctly inside the constructor, but then later, that same function no longer works! Why is this? Does the lambda have a limited lifespan? #include <functional> #include <iostream> class LambdaStore { public: LambdaStore(const std::function<void(float)>& _fn) : fn(_fn) { fn(11.1f); //…
-
Is constructing an object in an argument list and passing a pointer to internal data of the object to the function safe?
8 Is the C++ code below well-formed? Will the std::string get destroyed before or after the function finishes executing? void my_function(const char*); … my_function(std::string("Something").c_str()); c++ string temporary-objects Share Improve this question Follow edited 9 hours ago Evg 25k55 gold badges3939 silver badges8383 bronze badges asked 11 hours ago BlueCannonBallBlueCannonBall 13311 silver badge33 bronze badges 4…
-
Passing a pointer to a type that is privately inherited in some base class
18 I always assumed that private inheritance simply means that a type doesn’t tell the outside that it’s inheriting from some base class. However, it seems that there are more restrictions. Consider the following minimal example: struct MyInterface {}; struct MyImpl : private MyInterface {}; struct Inherited : public MyImpl { // Error: ‘MyInterface’ not…
-
What’s the significance of a C function declaration in parentheses apparently forever calling itself?
22 In gatomic.c of glib there are several function declarations that look like this: gboolean (g_atomic_int_compare_and_exchange_full) (gint *atomic, gint oldval, gint newval, gint *preval) { return g_atomic_int_compare_and_exchange_full (atomic, oldval, newval, preval); } Can someone explain what this code exactly does? I’m confused by several things here: The function name g_atomic_int_compare_and_exchange_full is in parentheses. What’s the…