Defines an error code. We do not use the same pattern as the standard library. The goal is to ensure an error code can consume a single register to ensure maximum compatibility with different CPU archiectures that only have a 32bit return register. We also do not use an enum to ensure custom error codes can be created. This also means there are no error code categories. Instead, an error code is checked if it is negative, and unchecked if it is positive to align with AUTOSAR. Finally, we provide the ability to change the type that an error code uses under the hood which allows you to use a "long" type, or some other integer type depending on your requirements (i.e., NTSTATUS).
More...
#include <basic_errc_type.hpp>
|
constexpr | basic_errc_type (value_type const &errc=SUCCESS) noexcept |
| Value initialization constructor. More...
|
|
| ~basic_errc_type () noexcept=default |
| Destroyes a previously created bsl::basic_errc_type.
|
|
constexpr | basic_errc_type (basic_errc_type const &o) noexcept=default |
| copy constructor More...
|
|
constexpr | basic_errc_type (basic_errc_type &&o) noexcept=default |
| move constructor More...
|
|
constexpr basic_errc_type & | operator= (basic_errc_type const &o) &noexcept=default |
| copy assignment More...
|
|
constexpr basic_errc_type & | operator= (basic_errc_type &&o) &noexcept=default |
| move assignment More...
|
|
template<typename O > |
| basic_errc_type (O val) noexcept=delete |
| This constructor allows for single argument constructors without the need to mark them as explicit as it will absorb any incoming potential implicit conversion and prevent it. More...
|
|
constexpr const_reference_type | get () const noexcept |
| Returns the integer value that represents the error code. Normally, this function should not be used, and instead, you should use the other functions like ==, !=, operator bool(), is_checked() and is_unchecked(). More...
|
|
constexpr bool | success () const noexcept |
| Returns true if the error code contains SUCCESS, otherwise, if the error code contains an error code, returns false. More...
|
|
constexpr bool | failure () const noexcept |
| Returns true if the error code contains an error code, otherwise, if the error code contains SUCCESS, returns false. More...
|
|
constexpr bool | is_checked () const noexcept |
| Returns true if the error code is a checked error (i.e., that is the error code is negative), false otherwise. If this error code is bsl::errc_success, returns false. More...
|
|
constexpr bool | is_unchecked () const noexcept |
| Returns true if the error code is an unchecked error (i.e., that is the error code is positive), false otherwise. If this error code is bsl::errc_success, returns false. More...
|
|
constexpr bsl::string_view | message () const noexcept |
| Returns a human readable version of the error code. If the error code is a custom, user defined error code, returns a nullptr. More...
|
|
|
(Note that these are not member functions.)
|
using | errc_type = basic_errc_type<> |
| provides the default errc_type prototype More...
|
|
template<typename T1 , T1 SUCCESS1, typename T2 , T2 SUCCESS2> |
constexpr bool | operator== (basic_errc_type< T1, SUCCESS1 > const &lhs, basic_errc_type< T2, SUCCESS2 > const &rhs) noexcept |
| Returns true if the lhs is equal to the rhs, false otherwise. More...
|
|
template<typename T1 , T1 SUCCESS1, typename T2 , T2 SUCCESS2> |
constexpr bool | operator!= (basic_errc_type< T1, SUCCESS1 > const &lhs, basic_errc_type< T2, SUCCESS2 > const &rhs) noexcept |
| Returns false if the lhs is equal to the rhs, true otherwise. More...
|
|
template<typename T = bsl::int32, T SUCCESS = 0>
class bsl::basic_errc_type< T, SUCCESS >
Defines an error code. We do not use the same pattern as the standard library. The goal is to ensure an error code can consume a single register to ensure maximum compatibility with different CPU archiectures that only have a 32bit return register. We also do not use an enum to ensure custom error codes can be created. This also means there are no error code categories. Instead, an error code is checked if it is negative, and unchecked if it is positive to align with AUTOSAR. Finally, we provide the ability to change the type that an error code uses under the hood which allows you to use a "long" type, or some other integer type depending on your requirements (i.e., NTSTATUS).
namespace bsl
{
inline void
example_basic_errc_type_overview() noexcept
{
}
}
if (my_errc.failure()) {
}
if (my_errc.is_unchecked()) {
}
}
}
◆ basic_errc_type() [1/4]
template<typename T = bsl::int32, T SUCCESS = 0>
Value initialization constructor.
namespace bsl
{
inline void
example_basic_errc_type_constructor_t() noexcept
{
constexpr basic_errc_type<> my_errc{errc};
if (my_errc.get() == errc) {
}
}
}
SUPPRESSION: PRQA 2180 - exception required
- We suppress this because A12-1-4 states that all constructors that are callable from a fundamental type should be marked as explicit. This is a fundamental type, but all implicit conversions are disabled through the use of the implicit general template constructor that is deleted which absorbs all incoming potential implicit conversions.
- Parameters
-
errc | the error code to store |
◆ basic_errc_type() [2/4]
template<typename T = bsl::int32, T SUCCESS = 0>
copy constructor
- Parameters
-
◆ basic_errc_type() [3/4]
template<typename T = bsl::int32, T SUCCESS = 0>
move constructor
- Parameters
-
◆ basic_errc_type() [4/4]
template<typename T = bsl::int32, T SUCCESS = 0>
template<typename O >
This constructor allows for single argument constructors without the need to mark them as explicit as it will absorb any incoming potential implicit conversion and prevent it.
SUPPRESSION: PRQA 2180 - false positive
- We suppress this because A12-1-4 states that all constructors that are callable from a fundamental type should be marked as explicit. This is callable with a fundamental type, but it is marked as "delete" which means it does not apply.
- Template Parameters
-
O | the type that could be implicitly converted |
- Parameters
-
val | the value that could be implicitly converted |
◆ operator=() [1/2]
template<typename T = bsl::int32, T SUCCESS = 0>
copy assignment
- Parameters
-
- Returns
- a reference to *this
◆ operator=() [2/2]
template<typename T = bsl::int32, T SUCCESS = 0>
move assignment
- Parameters
-
- Returns
- a reference to *this
◆ get()
template<typename T = bsl::int32, T SUCCESS = 0>
Returns the integer value that represents the error code. Normally, this function should not be used, and instead, you should use the other functions like ==, !=, operator bool(), is_checked() and is_unchecked().
namespace bsl
{
inline void
example_basic_errc_type_get() noexcept
{
constexpr basic_errc_type<> my_errc{errc};
if (my_errc.get() == errc) {
}
}
}
- Returns
- Returns the integer value that represents the error code.
◆ success()
template<typename T = bsl::int32, T SUCCESS = 0>
Returns true if the error code contains SUCCESS, otherwise, if the error code contains an error code, returns false.
namespace bsl
{
inline void
example_basic_errc_type_success() noexcept
{
}
}
}
- Returns
- Returns true if the error code contains SUCCESS, otherwise, if the error code contains an error code, returns false.
◆ failure()
template<typename T = bsl::int32, T SUCCESS = 0>
Returns true if the error code contains an error code, otherwise, if the error code contains SUCCESS, returns false.
namespace bsl
{
inline void
example_basic_errc_type_failure() noexcept
{
constexpr basic_errc_type<> my_errc{42};
if (my_errc.failure()) {
}
}
}
- Returns
- Returns true if the error code contains an error code, otherwise, if the error code contains SUCCESS, returns false.
◆ is_checked()
template<typename T = bsl::int32, T SUCCESS = 0>
Returns true if the error code is a checked error (i.e., that is the error code is negative), false otherwise. If this error code is bsl::errc_success, returns false.
namespace bsl
{
inline void
example_basic_errc_type_is_checked() noexcept
{
constexpr basic_errc_type<> my_errc{-42};
if (my_errc.is_checked()) {
}
}
}
- Returns
- Returns true if the error code is a checked error (i.e., that is the error code is negative), false otherwise. If this error code is bsl::errc_success, returns false.
◆ is_unchecked()
template<typename T = bsl::int32, T SUCCESS = 0>
Returns true if the error code is an unchecked error (i.e., that is the error code is positive), false otherwise. If this error code is bsl::errc_success, returns false.
namespace bsl
{
inline void
example_basic_errc_type_is_unchecked() noexcept
{
constexpr basic_errc_type<> my_errc{42};
if (my_errc.is_unchecked()) {
}
}
}
- Returns
- Returns true if the error code is an unchecked error (i.e., that is the error code is positive), false otherwise. If this error code is bsl::errc_success, returns false.
◆ message()
template<typename T , T SUCCESS>
Returns a human readable version of the error code. If the error code is a custom, user defined error code, returns a nullptr.
namespace bsl
{
inline void
example_basic_errc_type_message() noexcept
{
}
}
- Returns
- Returns a human readable version of the error code. If the error code is a custom, user defined error code, returns a nullptr.
◆ errc_type
template<typename T = bsl::int32, T SUCCESS = 0>
provides the default errc_type prototype
◆ operator==()
template<typename T1 , T1 SUCCESS1, typename T2 , T2 SUCCESS2>
Returns true if the lhs is equal to the rhs, false otherwise.
namespace bsl
{
inline void
example_basic_errc_type_equals() noexcept
{
constexpr basic_errc_type<> my_errc1{errc1};
constexpr basic_errc_type<> my_errc2{errc2};
if (my_errc1 == my_errc2) {
}
}
}
- Parameters
-
lhs | the left hand side of the operator |
rhs | the right hand side of the operator |
- Returns
- Returns true if the lhs is equal to the rhs, false otherwise
◆ operator!=()
template<typename T1 , T1 SUCCESS1, typename T2 , T2 SUCCESS2>
Returns false if the lhs is equal to the rhs, true otherwise.
namespace bsl
{
inline void
example_basic_errc_type_not_equals() noexcept
{
constexpr basic_errc_type<> my_errc1{errc1};
constexpr basic_errc_type<> my_errc2{errc2};
if (my_errc1 != my_errc2) {
}
}
}
- Parameters
-
lhs | the left hand side of the operator |
rhs | the right hand side of the operator |
- Returns
- Returns false if the lhs is equal to the rhs, true otherwise
The documentation for this class was generated from the following files: