-
Notifications
You must be signed in to change notification settings - Fork 258
[QUESTION] Is there any difference between 10 as int
and :int = 10
?
#306
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
It is just a matter of your intentions. In general, the syntax is as follows: {name}: {type} = {value};
You cannot mix the above points - you can skip only one part at a time. And this syntax works everywhere (one of the goals of cppfront: is to have context-free syntax). The cool thing I have discovered in the past is:
|
Maybe not for those types. |
Question: What is the preferred way of declaring variables out of these two ways? number1 := 10 as u64;
number2 : u64 = 10; or for contructor calls vec1 := (1,2) as std::vector;
vec2 : std::vector = (1,2); Which is the preferred and faster (if any) way? Plus, how do I create a vector of N elements with each value k? Can't figure that out |
If
I think this was discussed at #193. |
I cannot check it now but I think that vec1 := (1,2) as std::vector; Might not compile. |
Seems like no real solution was reached. This kind of problem would've been easily solved by named contructors as described in the parameter passing paper. But here's one solution I want to propose from one of the options Herb describes in issue #193: Use Herb says that the problem with this is that it is difficult to distinguish it from subscript operator, so we can try this: arr := [,1,2,3,4]; An extra comma at the start! |
@AbhinavK00 in the Suggestion template @hsutter emphasise:
I am not against it but please don't expect them to be included as it is not supporting Herb goals. |
I'm sorry but they're actual features not just syntax change. I'm trying a way to do away with initialiser lists, can't think of a full proposal so I just suggest small changes. |
|
Do we have initializer lists in cpp2? |
We have parentheses. With Cpp2 initialization, it compiles down to a braced-init-list.
|
Yea, but it's the cpp1 way. Cpp2 way would be something like
That's how we do it with classes in cpp2, the only one and right way. |
|
So in a nutshell, |
Therefore the result of both is the same but in different approaches for static casting. |
The following
as
and:type
examples do the same thing:I'm thinking can we consider they are the same but in different syntaxes?
The text was updated successfully, but these errors were encountered: