Giter Club home page Giter Club logo

Comments (6)

filipsajdak avatar filipsajdak commented on August 18, 2024

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.

jgarvin avatar jgarvin commented on August 18, 2024

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.

JohelEGP avatar JohelEGP commented on August 18, 2024

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.

filipsajdak avatar filipsajdak commented on August 18, 2024

Please learn the cpp2 syntax from files starting with pure2-. These are the files that have only cpp2 syntax.

from cppfront.

hsutter avatar hsutter commented on August 18, 2024

@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.

hsutter avatar hsutter commented on August 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.