Closed narizhny closed 7 years ago
@narizhny - thanks for the PR! Could you add unit tests for the casts? And could you share a use-case for this usage if you have one?
@artemp Yes, I'll do it.
What's the use-case for this? Is this to replicate the interface in http://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast
if so we're missing a few casts here. If not, why not simply get the underlying value and let the user cast herself? Not sure if a larger API surface is a good thing here.
static cast is usefull, where all types derived from one
class VehicleBase
{
public:
~VehicleBase(){}
void run() {}
};
class Car: public VehicleBase {};
class Bus: public VehicleBase {};
class Tracktor: public VehicleBase {};
using Vehicle = mapbox::util::variant<Car, Bus, Tracktor>;
std::vector<Vehicle> garage;
//I need to run all vehicles! What should i do? Write visitor? if-else-if-else..., or just
for(auto &v: garage)
mapbox::util::static_variant_cast<VehicleBase>(v).run();
const and reinterpret casts? Hmm... I didn't think about it.