C++ developments

May 9, 2025 at 3:05pm
May 9, 2025 at 11:20pm
One of the biggest features I want to see is the ability for an array to hold multiple types. Would make it easier to return a bunch of different types of information from a function.

There's always workarounds, but nothing beats just returning an array containing all the values.
May 10, 2025 at 2:52am
zapshe wrote:
There's always workarounds, but nothing beats just returning an array containing all the values.


Have you heard of std::tuple<> ?

Or do you have some other sort of meaning or requirement?


https://en.cppreference.com/w/cpp/utility/tuple
May 10, 2025 at 3:06am
Yes I use std::tuple. I like it, but its not as convenient. Don't like the "std::get<>" syntax much. You can't add more elements to it easily as you could something like a vector.

I was thinking similar to a Python array which could easily hold and deal with multiple types.

I don't think this kind of thing will ever come to C++ though.
May 10, 2025 at 9:01am
Don't like the "std::get<>" syntax much


There's Structured Bindings to unpack a tuple.

Have you looked at std::any and std::variant? You can have a std::vector of these.
https://en.cppreference.com/w/cpp/utility/any
https://en.cppreference.com/w/cpp/utility/variant
May 10, 2025 at 9:33am
That actually seems pretty neat, I haven't used std::variant before. I might mess with that later.

But it seems more like for fun or something to use in a pinch rather than a real convenient solution.
May 11, 2025 at 4:43am
Also, tuples can be concatenated, so I guess one could go with the idea of: this tuple plus some combination of these other tuples.

May 11, 2025 at 4:45am
There may be some wrapper one can build around these features to create something highly convenient, but it would end up being really slow I imagine.
May 12, 2025 at 4:23am
The std::variant was ruined by committee. Use boost::variant instead.
https://www.boost.org/doc/libs/release/doc/html/variant.html
Last edited on May 12, 2025 at 4:23am
Registered users can post here. Sign in or register to post.