Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
refined_typedef.h File Reference

(5212645b4665917019a96ba873d9e98c1a136b5f)

#include <QtCore/qglobal.h>
#include <functional>
#include <optional>
#include <type_traits>
+ Include dependency graph for refined_typedef.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define QDOC_REFINED_TYPEDEF(_type, _name)
 \macro QDOC_REFINED_TYPEDEF(_type, _name)
 

Macro Definition Documentation

◆ QDOC_REFINED_TYPEDEF

#define QDOC_REFINED_TYPEDEF ( _type,
_name )

\macro QDOC_REFINED_TYPEDEF(_type, _name)

Declares a wrapper type for {_type}, with identifier {_name}, that represents a subset of {_type} for which some conditions hold.

For example:

QDOC_REFINED_TYPEDEF(std::size_t, Fin5) {
return (value < 5) : std::make_optional<Fin5>{value} : std::nullopt;
}
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define QDOC_REFINED_TYPEDEF(_type, _name)
\macro QDOC_REFINED_TYPEDEF(_type, _name)

Represents the subset of {std::size_t} that contains the value 0, 1, 2, 3 and 4, that is, the general finite set of cardinality 5.

As the example shows, usages of the macro require some type, an identifier and some code.

The type that is provided is the type that will be wrapped. Do note that we expect a type with no-qualifiers and that is not a pointer type. Types passed with those kind of qualifiers will be simplified to their base type.

That is, for example, {int*}, {const int}, {const int&}, {int&} all counts as {int}.

The identifier that is passed is used as the name for the newly declared type that wraps the original type.

The code block that is passed will be run when an instance of the newly created wrapper type is being obtained. If the wrapper type is T, the codeblock must return a {std::optional<T>}. The code block should perform any check that ensures that the guarantees provided by the wrapper type holds and return a value if such is the case, otherwise returning {std::nullopt}.

Inside the code block, the identifier {value} is implicitly bound to an element of the wrapped type that the instance is being built from and for which the guarantees provided by the wrapper type must hold.

When a call to QDOC_REFINED_TYPEDEF is successful, a type with the provided identifier is declared.

Let T be a type declared trough a call of QDOC_REFINED_TYPEDEF and W be the type that it wraps.

An instance of T can be obtained by calling T::refine with an element of W.

If the element of W respects the guarantees that T provides, then the call will return an optional that contains an instance of T, othewise it will return an empty optional.

When an instance of T is obtained, it will wrap the element of W that was used to obtain it.

The wrapped value can be accessed trough the {value} method.

For example, considering {Fin5}, we could obtain an instance of it as follows:

auto instance = *(Fin5::refine(std::size_t{1}));

With that instance available we can retrieve the original value as follows:

instance.value(); // The value 1

Definition at line 131 of file refined_typedef.h.