Skip to content

melang982/cpp26-reflection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

C++26 ECS Reflection Demo

Minimal demo showing how C++26 reflection enables automatic inspector/serialization for ECS components without macros.

Requirements

  • GCC trunk (with reflection support merged Jan 2026)
  • Linux (tested on Ubuntu)

Building GCC Trunk

# Install dependencies
sudo apt install build-essential libgmp-dev libmpfr-dev libmpc-dev flex bison

# Clone GCC trunk
git clone git://gcc.gnu.org/git/gcc.git gcc-trunk
cd gcc-trunk

# Build (out-of-source required)
mkdir build && cd build
../configure --prefix=$HOME/gcc-trunk-install \
             --enable-languages=c,c++ \
             --disable-multilib \
             --disable-bootstrap
make -j$(nproc)
make install

Build takes ~10-45 minutes depending on hardware.

Compile and Run

cd ecs_reflection_demo
$HOME/gcc-trunk-install/bin/g++ -std=c++26 -freflection main.cpp -o demo
./demo

Expected Output

>>> INSPECTOR VIEW <<<

=== Transform ===
  [vec3]  position: [10.00, 5.00, -3.00]
  [vec3]  rotation: [0.00, 45.00, 0.00]
  [vec3]  scale: [1.00, 1.00, 1.00]

=== RigidBody ===
  [float] mass: 75.000
  [float] drag: 0.500
  [float] angular_drag: 0.050
  [bool]  use_gravity: true
  [bool]  is_kinematic: false

...

Key Reflection Features

Syntax Purpose
^^Type Reflect on a type
[:refl:] Splice reflection back to code
std::meta::nonstatic_data_members_of() Get struct fields
std::meta::identifier_of() Get field name
std::define_static_array() Convert to constexpr array
template for Expansion statement

GCC-specific Notes

  • Requires -freflection flag
  • nonstatic_data_members_of() needs access_context::current() parameter
  • Use std::define_static_array() to make ranges constexpr-compatible

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors