Skip to content

Commit 923beea

Browse files
committed
Add type_of as an easier way to spell CPP2_TYPEOF
I've been meaning to do this for over a year, it's time I'd prefer `typeof`, but that would conflict with C++ compilers that implement C `typeof` in C++ mode
1 parent 3a2d11e commit 923beea

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

docs/cpp2/common.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ main: () = {
105105
```
106106

107107

108-
## <a id="keywords"></a> Reserved keywords
108+
## <a id="keywords"></a> Contextual keywords
109109

110110
Cpp2 has very few globally reserved keywords; nearly all keywords are contextual, where they have their special meaning when they appear in a particular place in the grammar. For example:
111111

@@ -115,6 +115,8 @@ Cpp2 has very few globally reserved keywords; nearly all keywords are contextual
115115

116116
- `type` can be used as an ordinary name (e.g., `std::common_type<T1,T2>::type`).
117117

118+
- Unqualified `type_of(x)` is a synonym for Cpp1 `std::remove_cvref_t<decltype(x)>`.
119+
118120
In rare cases, usually when consuming code written in other languages, you may need to write a name that is a reserved keyword. The way to do that is to prefix it with `__identifer__`, which treats it as an ordinary identifier (without the prefix).
119121

120122

source/to_cpp1.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,9 @@ class cppfront
16791679
{
16801680
printer.print_cpp2("cpp2_"+n.to_string(), pos);
16811681
}
1682+
else if (n == "type_of") {
1683+
printer.print_cpp2("CPP2_TYPEOF", pos);
1684+
}
16821685
else {
16831686
printer.print_cpp2(n, pos, true);
16841687
}

0 commit comments

Comments
 (0)