Skip to content

Instantly share code, notes, and snippets.

@IS4Code
Created February 22, 2021 10:23
Show Gist options
  • Save IS4Code/a061bb37fd431ed29cb6858fb30ea0a9 to your computer and use it in GitHub Desktop.
Save IS4Code/a061bb37fd431ed29cb6858fb30ea0a9 to your computer and use it in GitHub Desktop.
C++ reflection idea
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