Home -> SuccessToken

Declaration

class SuccessToken;

Description

This is a lightweight type which is implicitly convertible to and from bool, and takes up one byte of storage. When the calling application is compiled in release mode, this type effectively does nothing, and adds no overhead over a normal bool. When the calling application is compiled in debug mode however, this type adds a custom destructor which detects when the value stored in this type hasn't been read by the application. By default, if a SuccessToken is destroyed before its value has been read using the Succeeded or Failed methods, or had the conversion operator to type bool performed, this type will trigger an assertion failure.

You are able to work with this type as if it doesn't exist at all, and just treat all SuccessToken types as if they were of type bool. For example:

if (!SomeMethod())
{
    _log.Error("SomeMethod returned false!");
    return;
}

In this case, it doesn't matter if SomeMethod returns bool or SuccessToken, it will behave identically. If you were to call SomeMethod without checking its return value however, as follows:

SomeMethod();

In this case, if SomeMethod returns a SuccessToken, an assertion failure may be triggered on this line in debug builds. The intention is to assist application developers in detecting missing error handling for API methods.

Members

Constructors

Name Description
Public member Constructor
Creates a SuccessToken object.

Operators

Name Description
Public member ConversionBool
Implicitly converts this type to bool, marking the value as read.

Result methods

Name Description
Public member Succeeded
Returns true if this type was constructed with the boolean value of true.
Public member Failed
Returns true if this type was constructed with the boolean value of false.
Public member IgnoreResult
Marks the value as read.