nkr
A C++20 library with a custom meta-programming language.
Typedefs
nkr::interface::none Namespace Reference

None interfaces handle semantics revolving around the lack of something. More...

Typedefs

template<typename type_p >
using value_i = typename nkr::interface::none::value_i_sp< type_p >::type_t
 Allows for the construction of a type instance that semantically indicates a missing value. More...
 

Detailed Description

None interfaces handle semantics revolving around the lack of something.

Typedef Documentation

◆ value_i

template<typename type_p >
using nkr::interface::none::value_i = typedef typename nkr::interface::none::value_i_sp<type_p>::type_t

Allows for the construction of a type instance that semantically indicates a missing value.

For a concrete example, say you design a type that is essentially a dynamically remote array of random numbers stored on the heap. Perhaps exceptions are ruled-out of your design, so you set the pointer on your instance to nullptr to indicate memory allocation has failed. However by default you want to avoid being pessimistic and allow your type to allocate memory and produce a valid value for your users. That means having a default constructor set the instance to an invalid state by default is out of the question.

Making an interface implementation for nkr::interface::none::value_i in this situation and all situations that involve memory allocation without exceptions is a reasonable solution to the problem. In the rare event that you failed to produce a value and literally have none to give, you can direct the interface to return an invalid instance as the none value.

However, if you're using a local array with a similar problem set, perhaps the nkr::interface::none_i would be more suitable, which only requires a boolean check of an already existing value to determine if it equals none, avoiding any need to create a potentially large instance just for literal comparison. nkr::interface::none::value_i is useful for when a none value must be produced and not only if an already existing none value needs to be compared.