Created
February 22, 2021 10:23
-
-
Save IS4Code/a061bb37fd431ed29cb6858fb30ea0a9 to your computer and use it in GitHub Desktop.
C++ reflection idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class std::identifier | |
{ | |
public: | |
template <size_t Size> | |
consteval identifier(const char (&name)[Size]); | |
consteval const char (&name() const)[auto]; | |
} | |
struct * | |
{ | |
template <std::identifier Id> | |
constexpr auto operator.*(); | |
template <std::identifier Id> | |
constexpr auto operator->*() | |
{ | |
return operator->().operator.*<Id>(); | |
} | |
/* | |
template <std::identifier Id> | |
constexpr auto operator.*<"operator.*">() | |
{ | |
return operator.*<Id>(); | |
} | |
template <std::identifier Id> | |
constexpr auto operator.*<"operator->*">() | |
{ | |
return operator->*<Id>(); | |
} | |
*/ | |
} | |
template <class T> | |
class wrapper | |
{ | |
T value; | |
public: | |
template <std::identifier Id> | |
auto operator.() | |
{ | |
return value.operator.*<Id>(); | |
} | |
template <> | |
auto operator.<"type">() | |
{ | |
return typeid(T); | |
} | |
template <class S> | |
auto operator.<"is">() | |
{ | |
return [](){return std::is_same_v<T, S>;}; | |
} | |
} | |
// w.a() --> w.operator.<"a">()() --> w.value.a() | |
// w.type --> w.operator.<"type">() | |
// w.is<int>() --> w.operator.<"is", int>()() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment