hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[SUGGESTION] Support "dot index" access for tuples as alternative for `std::get`

bluetarpmedia opened this issue · comments

Cpp2 could support tuple indexing expressions like Rust and Swift as syntactic sugar for std::get.

main: () -> int = {
    bag: std::tuple = (1, "test", 3.14);
    std::cout << bag.1 << "\n";         // Instead of std::get<1>(bag)
    return bag.0;                       // Instead of std::get<0>(bag)
}

Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code?
No

Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
No

Seems like something you could implement with Cpp1 reflection (I think it's in the paper).

Looks like operator[] might be an option for accessing tuple members because in terms of usage, tuple is a collection that can be accessed with indexes.
Also for example in Python the interface of tuple is similar to list with accessing with [index].

The index needs to be known at compile time though, as the return type depends on it.

The index needs to be known at compile time though, as the return type depends on it.

Yes, the tup.1 syntax proposed above would be lowered to std::get<1>(tup).

I know I was replying to the suggestion to use operator[]. Although maybe such a member function can indeed be written with Cpp2's existing tools?