Namespaces
Variants
Views
Actions

Compiletime Metaprogramming in C++ in P1717R0

From cppreference.com

Contents

[edit] Introduction

This is based on P0712.

template<typename... Types>
class tuple {
 consteval {
  int counter = 0;
  for... (meta::info type : reflexpr(Types)) {
   auto fragment = __fragment struct {
    typename(type) unqualid("element_", counter);
   };
   -> fragment;
   ++counter;
  }
 }
};
tuple<bool, char, int> tup;

same as

template<typename... Types>
class tuple {
 bool element0;
 char element1;
 int element2;
};


[edit] consteval{ ... }

the stuff filled in it is called metaprogram. It is executed where they appear in the translation unit.

[edit] typename( meta::info )

The typename of a reflection of a type can be gotten by typename operator.

[edit] unqualid

This operator makes a new unqualifiedid. It takes a few arguments, which are concatenated to form the new identifier.

[edit] ->fragment

This operator sends a request to the compiler. Compiler would inject the fragment.

[edit] __fragment
[edit] Class fragments

TODO:

[edit] Namespace Fragments

TODO:

[edit] Enum Fragment

TODO:

[edit] Block Fragments

TODO:

[edit] Parameterizing Fragments

TODO:

[edit] Nonlocal dependencies

TODO:

[edit] Parameter Injection

TODO:

[edit] Metaclasses

TODO:

[edit] See also

P1717R0