Welcome to 0.1 of the meta::[[verse]]!

# Slide 1

Reflection in C++

# Slide 2
  • The ability of software to expose its internal structure
  • Static reflection - compiler exposes structure at compile time
     
  • Disclaimers:
    • May be possible to "carry" the data into the runtime...
    • But may introduce performance, security, or other issues
    • This is out of scope for this talk (and for C++26, as of now)
# Slide 3

What do I mean by "Reflection"?

// Lib.hpp
class LibType : public BaseOne, public BaseTwo
{
   int a;
   double b;
};
P2996
// main.cpp
#include <meta>
#include "Lib.hpp"

int main()
{
   constexpr std::meta::info refexpr = ^^LibType;
   auto res = std::meta::bases_of(refexpr);
}

* Note: This is a pseudo-code, does not work as is

auto rexpr = ^int;
# Slide 4

The Reflection Operator (^) (Lift)

  • Shifts expressions into a "meta" - "reflection info" object
  • Object can then to be used as input to reflection utilities

error: meta type variables must be constexpr

constexpr auto rexpr = ^int;
P2996
# Slide 5

Splicers

  • Splice extract the C++ expression back from "meta::info"...
  • ...To be then used regularly to write the C++ program
constexpr auto rexpr = ^int;
typename[:rexpr:] a  = 42;
P2996
# Slide 6

P2996: Reflection for C++26

  1. Reflection Operator: ^

  2. Splicers: [::]

  3. std::meta::info

  4. Metafunctions

  1. identifier_of

  2. display_string_of

  3. source_location_of

  1. type_of

  2. parent_of

  3. dealias
     

  4. Access modifiers: is_public, is_protected, is_private

  5. Inheritance: is_virtual, is_pure_virtual, is_override, ...

  6. Encapsulation: is_class_member, is_namespace_member, is_explicit, is_deleted, ...

  7. Advanced Type Queries: is_complete_type, is_template, is_special_member, ...

  1. template_of

  2. template_arguments_of

3. Template Queries:

  1. members_of

  2. bases_of

  3. (non)static_data_members_of

  4. accessible_members_of (P3293R2)

  5. enumerators_of

​2. Type Queries:

  1. Name & Location:

(+ Other Type Predicates)

​4. Member Queries:

5. substitute (template)

6. reflect Invoke (template)

7. extract<T>(info) (constexpr not required)

8. test_type(s) ("is_same")

9. reflect_value (template)

10. define_class (injection)

11. Data Layout:

12. (+) Type Traits...?

P2996
  1. offset_of -> member_offsets

  2. size_of

  3. bit_size_of

  4. alignment_of

^^

What will we talk about?

# Slide 7
  • Part I: Intro to reflection:
    1. A brief history of "Reflection" proposals in C++
    2. Latest proposal: "P2996: Reflection for C++26"
    3. Usage examples (reflection-based library) (*)
  • Part II: Impact on our code bases
    1. Reflection as a Customization Point Mechanism
    2. Pipeline integration
    3. What's next?

(*) Examples from or derive from P2996, P3096, or EDG's implementation

# Slide 8

C++ 26 Reflection

How will Reflection impact our code bases?

Summary

?

From: https://isocpp.org/std/status (by Herb Sutter)

Intro: Welcome to the meta::[[verse]]

By Inbal Levi

Intro: Welcome to the meta::[[verse]]

  • 63