mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-28 22:06:19 +08:00
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
#include "test_enum7.hpp"
|
|
|
|
#include <cassert>
|
|
#include <iostream>
|
|
#include <rfl.hpp>
|
|
#include <rfl/json.hpp>
|
|
#include <source_location>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "write_and_read.hpp"
|
|
|
|
namespace test_enum7 {
|
|
|
|
enum class Color { red, green, blue, yellow };
|
|
|
|
struct Circle {
|
|
float radius;
|
|
Color color;
|
|
};
|
|
|
|
void test() {
|
|
std::cout << std::source_location::current().function_name() << std::endl;
|
|
|
|
constexpr auto enumerator_array = rfl::get_enumerator_array<Color>();
|
|
static_assert(enumerator_array[0].first == "red");
|
|
static_assert(enumerator_array[1].first == "green");
|
|
static_assert(enumerator_array[2].first == "blue");
|
|
static_assert(enumerator_array[3].first == "yellow");
|
|
static_assert(enumerator_array[0].second == Color::red);
|
|
static_assert(enumerator_array[1].second == Color::green);
|
|
static_assert(enumerator_array[2].second == Color::blue);
|
|
static_assert(enumerator_array[3].second == Color::yellow);
|
|
|
|
constexpr auto enumerator_array_underlying =
|
|
rfl::get_underlying_enumerator_array<Color>();
|
|
static_assert(enumerator_array_underlying[0].first == "red");
|
|
static_assert(enumerator_array_underlying[1].first == "green");
|
|
static_assert(enumerator_array_underlying[2].first == "blue");
|
|
static_assert(enumerator_array_underlying[3].first == "yellow");
|
|
static_assert(enumerator_array_underlying[0].second == 0);
|
|
static_assert(enumerator_array_underlying[1].second == 1);
|
|
static_assert(enumerator_array_underlying[2].second == 2);
|
|
static_assert(enumerator_array_underlying[3].second == 3);
|
|
|
|
// This is a compile-time test
|
|
std::cout << "OK" << std::endl << std::endl;
|
|
}
|
|
|
|
} // namespace test_enum7
|