Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cannot initialize std::map with initializer list #1037

Open
bluetarpmedia opened this issue Mar 21, 2024 · 0 comments · May be fixed by #927
Open

[BUG] Cannot initialize std::map with initializer list #1037

bluetarpmedia opened this issue Mar 21, 2024 · 0 comments · May be fixed by #927
Labels
bug Something isn't working

Comments

@bluetarpmedia
Copy link
Contributor

Describe the bug
I'd like to initialize a std::map (and other associative containers) with an initializer list or some other terse syntax similar to C++.

To Reproduce
I'm trying to translate the following C++ code into Cpp2:

std::map<std::string, int> m{{"CPU", 10}, {"GPU", 15}, {"RAM", 20}};

from the std::map example on cppreference.

This attempt fails:

m: std::map<std::string, int> = (("CPU", 10), ("GPU", 15), ("RAM", 20));

because it lowers to:

std::map<std::string,int> m {("CPU", 10), ("GPU", 15), ("RAM", 20)};

Both of the following succeed:

m: std::map<std::string, int> = (
        std::make_pair("CPU", 10),
        std::make_pair("GPU", 15),
        std::make_pair("RAM", 20));
m: std::map<std::string, int> = (
        :std::pair = ("CPU", 10),
        :std::pair = ("GPU", 15),
        :std::pair = ("RAM", 20));

But they don't have the same terse syntax as the original C++.

See also:
#568 - [BUG] Multidimensional std::array initialization

@bluetarpmedia bluetarpmedia added the bug Something isn't working label Mar 21, 2024
@JohelEGP JohelEGP linked a pull request Mar 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant