samedi 7 décembre 2019

Brace-enclosed initializer list for lambdas

I have the following code:

//visitor.h
template<class ... Ts>
struct overloaded: Ts... {
    using Ts::operator()...;
};

//main.cpp
int main() {
    auto PrintB = [](Book& b) {};
    auto PrintP = [](Pen& p) {};

    overloaded<decltype(PrintB), decltype(PrintP)> ts { PrintB, PrintP };
    return 0;
}

Compiling with Gcc 7 and c++11 support I have the following error:

../main.cpp: In function ‘int main()’: ../main.cpp:92:69: error: no matching function for call to ‘overloaded, main():: >::overloaded()’ overloaded ts { PrintB, PrintP }; ^ In file included from ../main.cpp:20:0: ../Visitor.h:24:8: note: candidate: constexpr overloaded, main():: >::overloaded(const overloaded, main():: >&) struct overloaded: Ts... { ^~~~~~~~~~ ../Visitor.h:24:8: note: candidate expects 1 argument, 2 provided ../Visitor.h:24:8: note: candidate: constexpr overloaded, main()::

::overloaded(overloaded, main():: >&&) ../Visitor.h:24:8: note: candidate expects 1 argument, 2 provided

I don't understand the error here. Any tips?

Aucun commentaire:

Enregistrer un commentaire