lundi 4 février 2019

Zero-cost lists for inline functions in c++

I like writing checks for a function over a list. For this I usually write a function like this:

    inline bool good_strings(const std::vector<const char *> & items)
    {
        for (i in items){
            if (not is_good(i)) return false;
        }
        return true;
    }

Then I can write like if (all_good({"a", "b", "c", "d", "e"})) {...} and it looks really nice. But i'm concerned with the overhead of the container I'm using, and also it's hard to choose one: std::vector, std::list, QList, QStringList or maybe even std::array or std::initializer_list - which should be used for inline functions? And which of these has minimum or even zero overhead when creating using the {} brackets?

Aucun commentaire:

Enregistrer un commentaire