Medium class used exclusively in the OR macro for safe reference handling 더 자세히 ...
#include <tmedium.hpp>
Public 멤버 함수 | |
| tmedium (T *value) | |
| tmedium (const T *value) | |
| operator T& () | |
| operator const T & () const | |
| operator nbool () const | |
| T * | operator-> () |
| const T * | operator-> () const BY_CONST_FUNC(operator->()) |
| nbool | has () const |
| T * | get () |
| const T * | get () const |
Medium class used exclusively in the OR macro for safe reference handling
The medium class is only used in the OR macro: one of the characteristics of the OR macro is that the final return value can be received as a reference. the fact that the final output type of this OR macro is always a reference type suggests that there is a logic to convert nullptr to a null reference and return it in the middle, even if the rhs entered into the OR macro is nullptr. sometimes, there are cases where you need to immediately wrap the T& returned by the OR macro with another container or wrapper class that can receive it. for example,
if you don't want to create two variables like above, you may want to do this:
but, there is one problem in this way. the c++ standard does not specify that the address value of a null reference is null. (and in fact, in an environment where optimized code is eval by clang on silicon macOS, referencing the address value of a nulled reference returns a garbage value.) so, when a null reference is received in the constructor of the tstr class, there is no way for the tstr class to determine whether it is correct or not.
then you might be thinking, Why not just make the OR macro return a T*?. if it returns T*, the meaning of using OR macro is greatly diminished. because users can no longer change from unsafe type to safe type easily, they might need to use some sort of c-style casting.
that's where tmedium class comes in. tmedium has the following purposes: