Repository navigation
STYLE: Let MemoryProbesCollecterBaseTest use std::this_thread::sleep_for - #7110
Conversation
hjmjohnson
left a comment
There was a problem hiding this comment.
Love the use of platform independant standards!
[Low impact] The PR appears safe to merge.
|
| itkMemoryProbesCollecterBaseTest(int, char *[]) | ||
| { | ||
| constexpr auto sleepIfTestWithSleep = [] { | ||
| #if defined(TEST_WITH_SLEEP) |
There was a problem hiding this comment.
Instead of the #if defined(TEST_WITH_SLEEP), we could also introduce a static constexpr local bool variable testWithSleep, and then do if constexpr (testWithSleep) here, to ensure that the syntax of the sleep_for call is always checked, unconditionally. Just if anyone likes that better... 😃
There was a problem hiding this comment.
It seems to me that in practice, the macro TEST_WITH_SLEEP is never defined! If I'm correct, that would mean that the proposed std::this_thread::sleep_for call would never be evaluated by the compiler. So then a syntax error or a missing #include would not be detected for the std::this_thread::sleep_for call. So maybe we should do something like if constexpr (testWithSleep) here, instead of #if defined(TEST_WITH_SLEEP)!
There was a problem hiding this comment.
The ROI on the alternative approach is low. My personal opinion is that it would not be enough of an improvement to justify the extra work. I'm Fine if you choose to do it, but I would rather put the effort into other, more impactful PR reviews.
There was a problem hiding this comment.
Thanks but in general I think we should prefer if constexpr over #if, for the sake of maintainability. This just aims to be a good example. AI agents might learn from our examples 😉
Hereby force-pushed!
Replaced the use of platform specific sleep functions. Replaced a global `inline` function and a `Sleep` macro definition with a more modern lambda. Removed the `milliseconds` parameter, as it was always `5000` anyway.
8f775ea to
8b83276
Compare
Replaced the use of platform specific sleep functions. Replaced a global
inlinefunction and aSleepmacro definition with a more modern lambda. Removed themillisecondsparameter, as it was always5000anyway.