Skip to content

Instantly share code, notes, and snippets.

View sudoLife's full-sized avatar

Matvei sudoLife

View GitHub Profile
@sudoLife
sudoLife / status_variable.hpp
Last active August 7, 2023 07:37
A C++ status variable class that throws when there is a status code indicating a problem.
// The status_variable class is a templated class that is used to handle the status
// of a variable with a predefined success code. Any assignment to this variable
// that does not match the success code results in an exception being thrown.
template <typename T>
class status_variable
{
public:
status_variable() = default;
explicit status_variable(int success_code) : success_code(success_code) {}
void operator=(T other)