lundi 29 janvier 2018

specify nested template parameters for function call

How I can specify types for template function when I call it?

#include <string>
#include <utility>
#include <boost/variant.hpp>

template <typename O, typename E, template <typename, typename> class VariantType>
VariantType<O, E> f(O o)
{
    return VariantType<O, E>{std::move(o)};
}

int main()
{
    boost::variant<int, std::string> res = 
     f<int, std::string, boost::variant<int, std::string>>(17);
}

clang reports such error(clang++ -Wall -std=c++11 test.cpp):

test.cpp: error: no matching function for call to 'f'
                boost::variant<int, std::string> res = f<int, std::string, boost::variant<int, std::string>>(17);
                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'VariantType'
VariantType<O, E> f(O o)

Aucun commentaire:

Enregistrer un commentaire