Added TypeDef.
This commit is contained in:
parent
6cac3a655b
commit
5e236dae00
82
source/mijin/types/typedef.hpp
Normal file
82
source/mijin/types/typedef.hpp
Normal file
@ -0,0 +1,82 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(MIJIN_TYPES_TYPEDEF_HPP_INCLUDED)
|
||||
#define MIJIN_TYPES_TYPEDEF_HPP_INCLUDED 1
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
|
||||
//
|
||||
// public defines
|
||||
//
|
||||
|
||||
#define MIJIN_TYPEDEF(name_, base_) \
|
||||
namespace impl { struct name_ ## _tag; } \
|
||||
using name_ = mijin::TypeDef<base_, impl::name_ ## _tag>
|
||||
|
||||
//
|
||||
// public constants
|
||||
//
|
||||
|
||||
//
|
||||
// public types
|
||||
//
|
||||
|
||||
template<typename TBase, typename TTag>
|
||||
class TypeDef
|
||||
{
|
||||
private:
|
||||
TBase value;
|
||||
public:
|
||||
TypeDef() = default;
|
||||
TypeDef(const TypeDef&) = default;
|
||||
TypeDef(TypeDef&&) = default;
|
||||
|
||||
template<typename... TArgs>
|
||||
constexpr TypeDef(TArgs&&... args) : value(std::forward<TArgs>(args)...) {}
|
||||
|
||||
TypeDef& operator=(const TypeDef&) = default;
|
||||
TypeDef& operator=(TypeDef&&) = default;
|
||||
|
||||
template<typename TArg>
|
||||
constexpr TypeDef& operator=(TArg&& arg)
|
||||
{
|
||||
value = std::forward<TArg>(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<typename TBase, typename TTag> requires (!std::is_fundamental_v<TBase>)
|
||||
class TypeDef<TBase, TTag> : public TBase
|
||||
{
|
||||
public:
|
||||
TypeDef() = default;
|
||||
TypeDef(const TypeDef&) = default;
|
||||
TypeDef(TypeDef&&) = default;
|
||||
template<typename... TArgs>
|
||||
constexpr TypeDef(TArgs&&... args) : TBase(std::forward<TArgs>(args)...) {}
|
||||
|
||||
TypeDef& operator=(const TypeDef&) = default;
|
||||
TypeDef& operator=(TypeDef&&) = default;
|
||||
|
||||
template<typename TArg>
|
||||
constexpr TypeDef& operator=(TArg&& arg)
|
||||
{
|
||||
TBase::operator=(std::forward<TArg>(arg));
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
} // namespace mijin
|
||||
#endif // !defined(MIJIN_TYPES_TYPEDEF_HPP_INCLUDED)
|
Loading…
x
Reference in New Issue
Block a user