C++ Visual Studio 2015无法推断模板参数(错误C2784)

C++ Visual Studio 2015无法推断模板参数(错误C2784),c++,c++11,visual-studio-2015,C++,C++11,Visual Studio 2015,我有一个简单的方法,它接受容器并将其内容连接到单个字符串中: namespace util { template <template <typename, typename...> class C, typename T> std::string to_string( const C<T> & elements, const std::string & separator = " " ) { std::stri

我有一个简单的方法,它接受容器并将其内容连接到单个字符串中:

namespace util {

    template <template <typename, typename...> class C, typename T>
    std::string to_string( const C<T> & elements, const std::string & separator = " " ) {
        std::stringstream xml;
        std::for_each( elements.begin(), elements.end(), [&]( const T & element ) {
            xml << element << separator;
        } );
        std::string result = xml.str();
        return result.substr( 0, result.size() - separator.size() );
    }

}
namespace-util{
模板
std::string到_string(常量C和元素,常量std::string和分隔符=”){
std::stringstreamxml;
std::for_each(elements.begin()、elements.end()、[&](const T&element){

xml
string
to_string
?在我看来,这似乎是可变模板的错误/不完整功能。请尝试
template
然后
const C&elements
。但是,作为一个参数的模板与作为容器的模式不匹配。这就解决了它。谢谢Yakk!
util::to_string( std::vector<int>({ 1, 3, 5 }) );
std::list<std::string> list = { "a", "b", "c" };
util::to_string( list );
error C2672: 'util::to_string': no matching overloaded function found
error C2784: 'std::string util::to_string(const C<T,> &,const std::string &)': could not deduce template argument for 'const C<T,> &' from 'std::vector<std::string,std::allocator<_Ty>>'