-
Notifications
You must be signed in to change notification settings - Fork 1.5k
testrunner: use structs with designated initialization to pass options #4975
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
Conversation
|
We can probably get rid of some of the redundant code with more macro magic. This is just an example. There's some tests which can profit even more than this. This might also help with some of the issues I will face using custom settings in some cases on my way to make settings immutable in tests. |
25b8104 to
f4442ed
Compare
test/helpers.h
Outdated
| ); | ||
| */ | ||
| #define dinit(T, ...) \ | ||
| ([&]{ T ${}; __VA_ARGS__; return $; }()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So doing dinit(S, $.i = 1, $.j = 2) wont evaluate the initialization in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should not be an issue in most of the cases. There are a few where that could be a problem though.
|
With some more macro stuff, you could improve this more: #define PRIMITIVE_APPLY(m, data, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x40, x41, x42, x43, x44, x45, x46, x47, x48, x49, x50, x51, x52, x53, x54, x55, x56, x57, x58, x59, x60, x61, x62, ...) \
m(x0, data) m(x1, data) m(x2, data) m(x3, data) m(x4, data) m(x5, data) m(x6, data) m(x7, data) m(x8, data) m(x9, data) m(x10, data) m(x11, data) m(x12, data) m(x13, data) m(x14, data) m(x15, data) m(x16, data) m(x17, data) m(x18, data) m(x19, data) m(x20, data) m(x21, data) m(x22, data) m(x23, data) m(x24, data) m(x25, data) m(x26, data) m(x27, data) m(x28, data) m(x29, data) m(x30, data) m(x31, data) m(x32, data) m(x33, data) m(x34, data) m(x35, data) m(x36, data) m(x37, data) m(x38, data) m(x39, data) m(x40, data) m(x41, data) m(x42, data) m(x43, data) m(x44, data) m(x45, data) m(x46, data) m(x47, data) m(x48, data) m(x49, data) m(x50, data) m(x51, data) m(x52, data) m(x53, data) m(x54, data) m(x55, data) m(x56, data) m(x57, data) m(x58, data) m(x59, data) m(x60, data) m(x61, data) m(x62, data)
#define APPLY(m, data, ...) PRIMITIVE_APPLY(m, data, __VA_ARGS__,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)
#define dinit_each(x, data) data x ;
#define dinit(T, ...) \
([&]{ T x{}; APPLY(dinit_each, x, __VA_ARGS__) return x; }())And then initialize with |
|
Very interesting - though a bit stomach turning. But I gotta look into the compiler errors on GCC 4.8 first though. I had to specify that strange |
danmar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think dinit is nice.
|
I will try to make it C++20 compliant first. |
|
Snarky comment: we wouldn't need any macros if we just switched to C++20 already... |
|
I decided to leave out several snarky remarks of my reply. 👺 C++20 is not fully supported by the compilers yet and even the existing parts appear to be quite buggy. And if we ever raise the C++ version I would prefer to go up incrementally to be able to track down performance, compiler time or other issues more easily. Also the used features should be upped incrementally since some of some can have some detrimental effects. Also variadic templates are not much better in reading and writing them. And my IDE shows me the resolved macros so that would actually be a plus for macros in my case. We should try to clean/fix up the existing things before opening new cans of worms... |
|
C++20 has designated initializers (https://en.cppreference.com/w/cpp/language/aggregate_initialization), not sure where variadic templates come into play. |
|
@pfultz2 The suggested C++20 compliant approach causes compiler warnings and is probably not working: Since it was already approved and making it compliant is a rather minor change afterwards I will commit this version for now. I also won't apply it broadly for now. It will be mainly for some targeted cases. This also blocks another pending change (cannot remember the specific one off the top my head). |
…s options (danmar#4975)" This reverts commit 5d201c4.
I need to add parameters to some
check()functions in the tests and things are already pretty messy with having to specify all the default values - readability aside.I found this on https://stackoverflow.com/a/49572324/532627 - apparently the CC BY-SA license by StackOverflow allows the usage within GPL.