mercredi 29 mars 2017

Variadic template argument deduction/substitution failed, metaprogramming

Im attempting to create a recursive template function, however I keep getting the error:

no matching function for call to meuPrint(int&, Separator&, string&)

while also receiving:

candidate: template string meuPrint(U ..., Separator&,string&).

struct Separator {};    

template<class ...U>
string meuPrint( U ...b , Separator &placeholder , string& text )
{//end
    char buffer[200];
    sprintf( buffer , text.c_str() , b... );
    return buffer;
}
template<class ...T, class ...U>
string meuPrint( U ...b , Separator &placeholder , string& text , string value , T ...a )
{//string
    return meuPrint( b... , to_lower( value ) , placeholder , text , a... );
}

template<class V, class ...T, class ...U>
string meuPrint( U ...b , Separator &placeholder , string& text , V value , T ...a )
{//middle
    return meuPrint( b... , value , placeholder , text , a... );
}

template<class ...T>
string meuPrint( std::string _text , T ...a )
{//start
    Separator placeholder;
    return meuPrint( placeholder , _text , a... );
}

int main( int n , char** args )
{
    string o = meuPrint(  string( "hello %i world" )  ,  8 );
    std::cout << o << std::endl;
    return 0;
}

The goal here isnt necessarily to lowercase the parameters, but to test a concept. I dont understand why the compiler keeps failing to deduce while telling me some valid candidates afterwards.

Aucun commentaire:

Enregistrer un commentaire