Comments (6)
The syntax for for loops in cpp2 is different. It should be rewritten to:
#include <vector>
main: () -> int = {
v : std::vector = (1, 2, 3, 4, 5);
i : int = 0;
for v do :(inout item : _) = {
if i > 3 {
v.resize(100);
}
i += 1;
}
}
(https://godbolt.org/z/d8o1bzMWc)
or using next
syntax
#include <vector>
main: () -> int = {
v : std::vector = (1, 2, 3, 4, 5);
i : int = 0;
for v next i++ do :(inout item : _) = {
if i > 3 {
v.resize(100);
}
}
}
When cppfront complain about braces you should check regression-tests
directory for some examples of syntax. For loops please check:
Please remember that in cpp2 sections you can use only cpp2 syntax.
from cppfront.
I got the syntax from a cpp2 regression test file already, I copied the last loop here: https://github.com/hsutter/cppfront/blob/main/regression-tests/mixed-intro-example-three-loops.cpp2
Why does it work there but not here?
from cppfront.
Seems like a lie. The whole file is Cpp1 syntax. If the function signature is not Cpp2 syntax, the body won't be parsed as Cpp2 syntax, AFAIK.
from cppfront.
Please learn the cpp2 syntax from files starting with pure2-
. These are the files that have only cpp2 syntax.
from cppfront.
@jgarvin wrote:
I was curious to see if cpp2 improvements included iterator invalidation safety
Not yet implemented, but planned. See this project's home page README.md > 2015: Lifetime safety section, which has links to the static analysis specification (part of the C++ Core Guidelines and videos showing a couple of Cpp1 demo implementations.
from cppfront.
@JohelEGP wrote:
The whole file is Cpp1 syntax.
Yes, a .cpp2 file can be all today's syntax. That particular file was one of a series of demos that shows gradual migration from Cpp1 syntax to Cpp2 syntax so it started with Cpp2 syntax, so I checked it in when I checked in all my other test/demo files.
from cppfront.
Related Issues (20)
- [BUG] cppfront fails on valid cpp1 syntax for importing module partitions
- [QUESTION] as should be able to cast a *void to a *char or *u8 (unsigned char) HOT 18
- [BUG] Cannot use `as` cast followed by multiplication operator without parens HOT 1
- [SUGGESTION] Add the equivalent of C++23 "deducing this" HOT 10
- [SUGGESTION] Only include `cpp2regex.h` when `@regex` is used to improve compile time HOT 5
- [BUG] raw string literals are not respected when lowered
- [SUGGESTION] clean up extra whitespace at the end of line for generated code
- [BUG] ICE when putting a ; after a type definition when there is a newline in the type body HOT 6
- [DOCS] Improve documentation on syntax for function return types
- [SUGGESTION] Allow `swap` to be a hidden friend
- [SUGGESTION] allow `: ==` for anonymous alias declarations (instead of `using`) HOT 7
- [BUG] using the using keyword inside a namespace with global functions results in code that does not compile
- [BUG] using using for operators fails
- [SUGGESTION] Documenting `==` as `constexpr` and using unified declaration syntax for aliases HOT 8
- [BUG] Confusion between postifx and binary use of `&` and `*` when keyword is part of the second argument. HOT 1
- [SUGGESTION] Creating an enum instance from a raw integer HOT 6
- [SUGGESTION] add special cases for [unique.]new and shared.new when using custom deleters
- [BUG] Constant static members not initialized inside class definition
- [BUG] New clone of repo shows modification to `pure2-regex_10_escapes.cpp.execution` HOT 5
- [BUG] Regression output dpends on temporary directory
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppfront.