Reflection for C++26
The P2996R4 document proposes a reduced set of static reflection features in C++26, using constant expressions, a reflection operator, metafunctions, and splicers. Implementation progress is ongoing by Lock3 and EDG.
Read original articleThe document P2996R4 dated 2024-06-26 proposes a reduced set of features for static reflection in C++26. It suggests using constant expressions to produce reflection values of an opaque type std::meta::info, a reflection operator (^), consteval metafunctions, and splicers to generate grammatical elements from reflections. The proposal aims to facilitate code generation based on program structure observations, known as reflective metaprogramming. It emphasizes starting with a smaller feature set to expedite inclusion in the language, with plans for future enhancements. Notable additions include metafunctions for synthesizing simple struct and union types. The document defends the use of a single opaque reflection type to avoid constraining language evolution and implementation advantages. Implementation status indicates ongoing work by Lock3 and EDG, with available implementations on Compiler Explorer. The implementations cover significant features proposed, including namespace and template splicers, with examples showcased in both implementations. However, some language features like expansion statements are not yet included.
Related
Own Constant Folder in C/C++
Neil Henning discusses precision issues in clang when using the sqrtps intrinsic with -ffast-math, suggesting inline assembly for instruction selection. He introduces a workaround using __builtin_constant_p for constant folding optimization, enhancing code efficiency.
How the STL Uses Explicit
The WG21 meeting in St. Louis discusses a paper on using the `explicit` keyword in C++ proposals to establish a style guide for consistency. Guidelines differ between industry and Standard Library practices.
The Inconceivable Types of Rust: How to Make Self-Borrows Safe
The article addresses Rust's limitations on self-borrows, proposing solutions like named lifetimes and inconceivable types to improve support for async functions. Enhancing Rust's type system is crucial for advanced features.
Elixir Anti-Patterns
The document discusses code-related anti-patterns in Elixir v1.18.0-dev, highlighting issues like comments overuse, complex 'with' expressions, dynamic atom creation, long parameter lists, and namespace conventions. It provides examples and refactoring suggestions to improve code quality and maintainability.
ECMAScript 2024: What's New?
Ecma International approved ECMAScript 2024 with new features like Promise.withResolvers(), /v flag for Unicode properties, ArrayBuffers enhancements, and Atomics.waitAsync(). Notable additions include resizing ArrayBuffers and string well-formedness methods. A book "Exploring JavaScript (ES2024 Edition)" is available.
Looking at the examples (https://isocpp.org/files/papers/P2996R4.html#examples) what really stands out is the direct integration of type-syntax into the language. It fits in with a certain token-substitution way that connects back to templates. It also replaces some of the uglier operators (typeof?).
I hope it goes int! During the language's stagnation I left for a while, perhaps it'll be competitive again soon.
1. how immense the language has become, and how hard it got to learn and implement
2. how "modernising" C++ gives developers less incentives to convince management to switch to safer languages
While I like C++ and how crazy powerful it is, I also must admit decades of using it that teaching it to new developers has become immensely hard in the last few years, and the "easier" inevitably ends up being the unsafe one (what else can you do when the language itself tells you to refrain from using `new`?).
More specifically, with this I can iterate over struct members and get their names and types, but I cannot attach additional information to these members, like whether they should be serialized or under which name.
The referenced proposal P1887R1 covers this, but that's not included here, right?
P1887R1: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p18...
* What type of problems static reflection could solve, in general?
* Are there specific cases and / or situations where static reflection could resolve such case, even simplify an unnecessary complexity?
But the `member_number` functions in § 3.2 look disturbing to me. It's not discernible how invalid arguments are handled. Normally I'd look at generated assembly to answer a question like that, but this probably doesn't make sense with compile-time-fu (`constexpr`)…
Related
Own Constant Folder in C/C++
Neil Henning discusses precision issues in clang when using the sqrtps intrinsic with -ffast-math, suggesting inline assembly for instruction selection. He introduces a workaround using __builtin_constant_p for constant folding optimization, enhancing code efficiency.
How the STL Uses Explicit
The WG21 meeting in St. Louis discusses a paper on using the `explicit` keyword in C++ proposals to establish a style guide for consistency. Guidelines differ between industry and Standard Library practices.
The Inconceivable Types of Rust: How to Make Self-Borrows Safe
The article addresses Rust's limitations on self-borrows, proposing solutions like named lifetimes and inconceivable types to improve support for async functions. Enhancing Rust's type system is crucial for advanced features.
Elixir Anti-Patterns
The document discusses code-related anti-patterns in Elixir v1.18.0-dev, highlighting issues like comments overuse, complex 'with' expressions, dynamic atom creation, long parameter lists, and namespace conventions. It provides examples and refactoring suggestions to improve code quality and maintainability.
ECMAScript 2024: What's New?
Ecma International approved ECMAScript 2024 with new features like Promise.withResolvers(), /v flag for Unicode properties, ArrayBuffers enhancements, and Atomics.waitAsync(). Notable additions include resizing ArrayBuffers and string well-formedness methods. A book "Exploring JavaScript (ES2024 Edition)" is available.