diff --git a/source/mijin/types/typedef.hpp b/source/mijin/types/typedef.hpp new file mode 100644 index 0000000..09cc240 --- /dev/null +++ b/source/mijin/types/typedef.hpp @@ -0,0 +1,82 @@ + +#pragma once + +#if !defined(MIJIN_TYPES_TYPEDEF_HPP_INCLUDED) +#define MIJIN_TYPES_TYPEDEF_HPP_INCLUDED 1 + +#include + +namespace mijin +{ + +// +// public defines +// + +#define MIJIN_TYPEDEF(name_, base_) \ +namespace impl { struct name_ ## _tag; } \ +using name_ = mijin::TypeDef + +// +// public constants +// + +// +// public types +// + +template +class TypeDef +{ +private: + TBase value; +public: + TypeDef() = default; + TypeDef(const TypeDef&) = default; + TypeDef(TypeDef&&) = default; + + template + constexpr TypeDef(TArgs&&... args) : value(std::forward(args)...) {} + + TypeDef& operator=(const TypeDef&) = default; + TypeDef& operator=(TypeDef&&) = default; + + template + constexpr TypeDef& operator=(TArg&& arg) + { + value = std::forward(arg); + return *this; + } + + explicit constexpr operator const TBase&() const noexcept { return value; } + explicit constexpr operator TBase&() noexcept { return value; } + auto operator<=>(const TypeDef&) const noexcept = default; +}; + +template requires (!std::is_fundamental_v) +class TypeDef : public TBase +{ +public: + TypeDef() = default; + TypeDef(const TypeDef&) = default; + TypeDef(TypeDef&&) = default; + template + constexpr TypeDef(TArgs&&... args) : TBase(std::forward(args)...) {} + + TypeDef& operator=(const TypeDef&) = default; + TypeDef& operator=(TypeDef&&) = default; + + template + constexpr TypeDef& operator=(TArg&& arg) + { + TBase::operator=(std::forward(arg)); + return *this; + } +}; + +// +// public functions +// + +} // namespace mijin +#endif // !defined(MIJIN_TYPES_TYPEDEF_HPP_INCLUDED)