mardi 30 juillet 2019

How to send parameter to function only if statement is matched?

I have a map, that I only want to send to a function if it has elements in it. The function takes a parameter pack so I can send how many or how few elements I want.

Is there a way to make the size-check of the map in the call itself? There are a lot of maps that will be sent in the same call meaning that it would be very tedious to do the check outside of the call itself.

pseudo-code of what I want:

std::map<int, int> a;
std::map<int, int> b;
std::map<int, int> c;
std::map<int, int> d;
fun( (if (a.size() > 0), (if (b.size() > 0), (if (c.size() > 0), (if (d.size() > 0));

I know this code is very wrong, but it is just to give you an idea of what I am after.

Aucun commentaire:

Enregistrer un commentaire