Content deleted Content added
Add from User:Moondezmon/C++26 Draft |
Tags: Mobile edit Mobile web edit |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 38:
* <code>alignas</code>
* <code>alignof</code>
* <code>and</code>▼
* <code>and_eq</code>▼
* <code>asm</code>
* <code>auto</code>
* <code>bitand</code>▼
* <code>bitor</code>▼
* <code>bool</code>
* <code>break</code>
Line 53 ⟶ 49:
* <code>char32_t</code>
* <code>class</code>
* <code>compl</code>▼
* <code>concept</code>
* <code>const</code>
Line 90 ⟶ 85:
* <code>new</code>
* <code>noexcept</code>
* <code>not</code>▼
* <code>not_eq</code>▼
* <code>nullptr</code>
* <code>operator</code>
* <code>or</code>▼
* <code>or_eq</code>▼
* <code>private</code>
* <code>protected</code>
Line 128 ⟶ 119:
* <code>wchar_t</code>
* <code>while</code>
* <code>xor</code>▼
* <code>xor_eq</code>▼
{{div col end}}
The keyword [[restrict|<code>restrict</code>]], though present in C, is not standard in C++, though some compilers may support it. The keyword <code>fortran</code>, a conditionally supported keyword in C which denotes linkage for the [[Fortran]] programming language, is conditionally supported in C++.
=== Alternative operator keywords ===
The following words are reserved keywords, but are used as alternative spellings for operators and tokens that use non-ISO646 characters.
{{div col|colwidth=15em}}
▲* <code>and</code>
▲* <code>and_eq</code>
▲* <code>bitand</code>
▲* <code>bitor</code>
▲* <code>compl</code>
▲* <code>not</code>
▲* <code>not_eq</code>
▲* <code>or</code>
▲* <code>or_eq</code>
▲* <code>xor</code>
▲* <code>xor_eq</code>
{{div col end}}
=== Identifiers with special meaning ===
Line 570 ⟶ 575:
class MyObject {
private:
[[no_unique_address]]
int x; public:
[[nodiscard]]
Line 644 ⟶ 650:
== Reflection ==
In addition to basic metaprogramming provided in header <code><type_traits></code>, [[C++26]] introduces compile-time reflection. Compile-time reflection capabilities can be accessed in header <code><meta></code> and declarations are stored in namespace <code>std::meta</code>.
=== Annotations ===
Most declarations can
<syntaxhighlight lang="cpp">
using custom::EnumFlag;
using custom::Rename;
enum class [[=EnumFlag]] Toggle: uint8_t {
Off,
On
};
struct [[=
[[=
std::string
int age;
};
Line 662 ⟶ 672:
The annotations have no initial meaning unless some implementations use those annotations to identify some characteristics and features.
Creating an annotation to generate a specialisation for <code>std::formatter<T></code> is as follows:
<syntaxhighlight lang="cpp">
template <auto V>
struct Derived {};
template <auto V>
inline constexpr Derived<V> Derive;
inline constexpr struct {} Debug;
template <typename T>
requires (std::meta::has_annotation(^^T, Derive<Debug>))
struct std::formatter<T> {
// ...
};
struct [[=Derive<Debug>]] Point {
int x;
int y;
};
int main() {
Point p = Point { .x = 1, .y = 2 };
// prints p = Point { .x = 1, .y = 2 }
std::println("p = {}", p);
}
</syntaxhighlight>
== See also ==
* [[C++ standard library]]
* [[C syntax]]
* [[Java syntax]]
* [[C Sharp syntax|C# syntax]]
* [[Rust syntax]]
|