Utilities¶
Output Types¶
#include <abstractions/types.h>
using namespace abstractions;
-
using abstractions::Error = std::optional<std::string>¶
Common error type.
This will be empty if the function or method returning the error type completed successfully. Otherwise it will return a string describing the reason for the error.
-
template<typename T>
using abstractions::Expected = std::expected<T, Error>¶ Stores the expected result of an operation.
If an error occurs then this will contain an Error value instead of the expected result type.
- Template Parameters:
T – expected result type
-
template<typename T>
class Options¶ A wrapper that allows enums to be used like a bitmask.
This is adapted from https://gpfault.net/posts/typesafe-bitmasks.txt.html.
- Template Parameters:
T – a scope enum type
Public Functions
-
inline constexpr Options(T value)¶
Create a new Options instance from the given value.
- Parameters:
value – enum value
-
inline constexpr void Set(T value)¶
Sets the bit corresponding to the given enum value.
- Parameters:
value – enum value
-
inline constexpr void Clear(T value)¶
Clears the bit corresponding to the given enum value.
- Parameters:
value – enum value
-
inline constexpr Options operator|(T other) const¶
Implements the
union = a | b
operation.- Parameters:
other – enum value
- Returns:
an updated MaskedOption
-
inline constexpr bool operator&(T value) const¶
Checks if the given bit is set in the masked option.
- Parameters:
value – enum value
- Returns:
whether or not the bit is set
-
inline constexpr bool operator!()¶
-
inline constexpr operator bool()¶
Exceptions and Error Handling¶
#include <abstractions/errors.h>
using namespace abstractions::errors;
-
class AbstractionsError : public std::runtime_error¶
Exception thrown when the abstractions library encounters a non-recoverable error.
This should only be caught in a program’s
main()
function to perform any last minute clean-up before terminating the program.