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

Variant initialization improvisation (suggestion) #600

Open
amutamil opened this issue Jan 1, 2024 · 4 comments
Open

Variant initialization improvisation (suggestion) #600

amutamil opened this issue Jan 1, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@amutamil
Copy link

amutamil commented Jan 1, 2024

when variant is declared without initialisation default constructor of variant construct with first data type mentioned. so can we include this in .

for example currently
variant <int, string> v; is compiled to
std::variant<int, std::basic_string<char> > v = std::variant<int, std::basic_string<char> >();.
but can we implement something like
std::variant <int, std::basic_string<char> > v = std::variant<int, std::basic_string<char> ><int, 0>(); which is more similar to MSVC compilation

@amutamil amutamil changed the title Variant initialization improvisation (sugession) Variant initialization improvisation (suggestion) Jan 1, 2024
@andreasfertig
Copy link
Owner

Hello @amutamil,

thank you for your feedback!

The implementation code you show as it could be isn't valid C++. The second pair of angle brackets is not allowed.

I agree that by default, variant constructs the first type. However, this is an implementation detail of std::variant and is not reflected in the AST. The only thing I see here would be adding a comment with the used initialization value. Sadly, that means that I would have to look for a special type that could also be aliased by, for example, a typedef. I'm not sure this is worth the effort, but I'm happy to accept a patch.

Andreas

@andreasfertig andreasfertig added the enhancement New feature or request label Jan 8, 2024
@amutamil
Copy link
Author

amutamil commented Jan 9, 2024

Hello Andres,
I would like to contribute to this repo,. Am a junior dev guy with just 2 year experience in C++ , proper C++ though just past 3 months :( if any resources explaining the code base or code walk through is available, it would much helpful to start for me.

@andreasfertig
Copy link
Owner

Hello @amutamil,

well, the issue is that C++ Insights uses LLVM/Clang. You need a bit of knowledge there and then find the right entry point for the transformation in C++ Insights. The latter is complex as there is more than just a bare variable declaration. One can also create temporary objects. As I said above, I don't think the feature is worth the effort.

Andreas

@amutamil
Copy link
Author

okay thanks :)

Amutamil E

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants