C++ developments

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.
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
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.
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
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.
Also, tuples can be concatenated, so I guess one could go with the idea of: this tuple plus some combination of these other tuples.

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.
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
Registered users can post here. Sign in or register to post.