mercredi 1 avril 2020

error: use of 'auto' in lambda parameter declaration only available with -std=c++1y or -std=gnu++1y [-Werror]

I have a template function that takes and puts it into output stream without worrying about the type. This is a C++ 14 compatible code which has auto as params to lambda. But, I need my compiler settings to be C++ 11. What changes do I make to resolve this so that it works with C++ 11 too.

Here is my code

template<class... Args >
std::string build_message( Args&&... args )
{

    auto aPrintImplFn = [](auto& os, auto&& ... ts) {
        // expression (void) just to suppress the unused variable warning
        (void)std::initializer_list<char> { (os << ts, '0')... };
    };

    std::ostringstream out;
    aPrintImplFn(out, std::forward<Args>(args)...);
    return out.str();
}

Aucun commentaire:

Enregistrer un commentaire