Is it really necessary to [[nodiscard]] the return value of the write() method? #1104
-
While refactoring our code I found a few places where I don't care whether the writing was successful, but the linter now generates a bunch of warnings .... I wonder if the library should really care about the usage of the return value. What do you think? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There are a few ways to clean up the code when you don't care about successful writing:
std::ignore = glz::write_json(value, buffer); This is probably what you want, albeit it requires a bit more code from the developer.
#include "glaze/glaze_exceptions.hpp"
glz::ex::write_json(value, buffer); Now, in the unlikely case of an error you'll get an exception, but you don't have to handle it here.
(void)glz::write_json(value, buffer); I would prefer |
Beta Was this translation helpful? Give feedback.
There are a few ways to clean up the code when you don't care about successful writing:
std::ignore
This is probably what you want, albeit it requires a bit more code from the developer.
Now, in the unlikely case of an error you'll get an exception, but you don't have to handle it here.
(void)glz::write_json(value, buffer);
I would prefer
std::ignore
because it is more obvious what is going on, but this is an alternative approach.