Reflection in C++

Reflection in C++ - Past, Present, and Hopeful Future - Andrei Alexandrescu - CppCon 2022

#include <meta>
template<Enum T>
std::string to_string(T value) { // Could also be marked constexpr
	template for (constexpr auto e : std::meta::members_of(^T)) {
		if ([:e:] == value) {
			return std::string(std::meta::name_of(e));
		}
	}
	return "<unnamed>";
}

see also

  • Circle lang - a new language that extends C++ 17 to support data-driven imperative metaprogramming. Circle combines the immediacy and flexibility of a scripting language with the type system, performance and universality of C++.
Written on May 11, 2023, Last update on May 11, 2023
c++ reflection