knowL: Knowledge Libraries
Loading...
Searching...
No Matches
NamedType.h
1#pragma once
2
3#include <type_traits>
4
5namespace knowCore
6{
8 {
9 enum {
10 None = 0,
22 Default = None,
23 };
24 };
38 template<typename _T_, typename _Tag_, int _Options_ = NamedTypeOptions::Default>
40 {
41 public:
42 explicit NamedType(const _T_& _value) : m_value(_value) {}
43 template<int _Options_2_ = _Options_, typename = std::enable_if_t<(_Options_2_ & NamedTypeOptions::ExplicitConversion) == 0>>
44 operator _T_() const
45 {
46 return m_value;
47 }
48 _T_ value() const {
49 return m_value;
50 }
51 private:
52 _T_ m_value;
53 };
54}
55
56#include "Formatter.h"
57
58template<typename _T_, typename _Tag_, int _Options_>
59struct fmt::formatter<knowCore::NamedType<_T_, _Tag_, _Options_>> : public fmt::formatter<_T_> {
60 using super = fmt::formatter<_T_>;
61 template <typename FormatContext>
62 auto format(const knowCore::NamedType<_T_, _Tag_, _Options_>& p, FormatContext& ctx) -> decltype(ctx.out())
63 {
64 return super::format(p, ctx);
65 }
66};
67
68namespace std
69{
70 // NamedTypes are trivial is their base type is trivial
71 template<typename _T_, typename _Tag_, int _Options_>
72 struct is_trivial<knowCore::NamedType<_T_, _Tag_, _Options_>>
73 : public std::is_trivial<_T_>
74 {
75 };
76}
Definition NamedType.h:40
Definition NamedType.h:8
@ ExplicitConversion
Definition NamedType.h:21