[meta.reflection.define.aggregate] (original) (raw)

21 Metaprogramming library [meta]

21.4.16 Reflection class definition generation [meta.reflection.define.aggregate]

namespace std::meta { struct data_member_options { struct name-type { template<class T> requires constructible_from<u8string, T> consteval name-type(T&&);template<class T> requires constructible_from<string, T> consteval name-type(T&&);private: variant<u8string, string> contents; }; optional<_name-type_> name; optional<int> alignment; optional<int> bit_width;bool no_unique_address = false;};}

template<class T> requires [constructible_from](concept.constructible#concept:constructible%5Ffrom "18.4.11 Concept constructible_­from [concept.constructible]")<u8string, T> consteval _name-type_(T&& value);

Effects: Initializes _contents_with u8string(std​::​forward<T>(value)).

Effects: Initializes _contents_with string(std​::​forward<T>(value)).

[Note 1:

The class name-type allows the function data_member_spec to accept an ordinary string literal (or string_view, string, etc.)

or a UTF-8 string literal (or u8string_view, u8string, etc.)

equally well.

[Example 1: consteval void fn() { data_member_options o1 = {.name = "ordinary_literal_encoding"}; data_member_options o2 = {.name = u8"utf8_encoding"};} — _end example_]

— _end note_]

consteval info data_member_spec(info type, data_member_options options);

Returns: A reflection of a data member description ([class.mem.general]) where

[Note 2:

The returned reflection value is primarily useful in conjunction with define_aggregate; it can also be queried by certain other functions in std​::​meta(e.g., type_of, identifier_of).

— _end note_]

Throws: meta​::​exception unless the following conditions are met:

consteval bool is_data_member_spec(info r);

Returns: true if r represents a data member description.

Otherwise, false.

template<[reflection_range](meta.reflection.substitute#concept:reflection%5Frange "21.4.14 Reflection substitution [meta.reflection.substitute]") R = initializer_list<info>> consteval info define_aggregate(info class_type, R&& mdescrs);

Let C be the class represented by class_typeand be the reflection value in mdescrs.

For every in mdescrs, let be the corresponding data member description represented by .

Constant When:

Effects: Produces an injected declaration D ([expr.const]) that defines C and has properties as follows: