vendredi 20 septembre 2019

How to make tuple of differing const-ness?

I have a function that returns several objects inside a tuple.

return std::tuple<std::vector<float>, class1, class2> (vec, instance1, instance2);

I feed this tuple into another function with signature:

void func(std::tuple<std::vector<float>, class1, class2> & data);

I want to modify class1, but not any of the other objects in the tuple. I've tried returning,

return std::tuple<const std::vector<float>, class1, const class2> (vec, instance1, instance2);

and modifying the signature.

void func(std::tuple<const std::vector<float>, class1, const class2> & data);

I might want to modify vec and class2 later so how can I make this function signature safe and use const correctly? Is returning a tuple with const members valid or better?

Aucun commentaire:

Enregistrer un commentaire