Checking whether a number starts with any of a list of string prefixes This code will return false if the long double rand begins with any string in the vector prefix.

bool prefix_vect(long double rand, std::vector&lt;std::string&gt; prefix) {
    std::string str_rand = std::to_string(rand);
    for(auto i : prefix) {
        if(boost::starts_with(str_rand, i))
            return false;
    }
    return true;
}


This code uses #include &lt;boost/algorithm/string/predicate.hpp&gt;.

How can I improve this code? Is there a way to make it fit into one line, such that it could be used without a function at all, and instead in an if-statement?

I am not experienced with C++ lambda expressions, is this something that could use them?

As a note: I don't care if it returns true or false, the Boolean can be switched if it makes this easier to optimize.

Edit: This isn't my main account, just a throwaway (unable to merge accounts, sadly).
It's better to pass containers as references to avoid copying like this:

bool prefix_vect(long double rand, const std::vector&lt;std::string&gt;&amp; prefix)


Also, when iterating on sequence, references also can improve performance:

for(const auto&amp; i : prefix) {


As for one-liner I'd used something like this:

bool prefix_vect2(long double rand, const std::vector&lt;std::string&gt;&amp; prefix) {
    std::string str_rand = std::to_string(rand);
    return std::none_of(prefix.begin(), prefix.end(),
             [&amp;str_rand](const std::string&amp; s){ return boost::starts_with(str_rand, s); });
}