Hi
I want to write nice join template function. In order to work with
different containers and with wide and narrow strings it must be template.
Now I have some thing like this:
/**
* @brief Joins strings in container.
* @param aStringList an container wiht strings.
* @param aDelimiter string witch joins strings in container.
* @result String joined with delimiter.
*/
template<template<typename> typename tContainer, typename tString>
tString gJoin(const tContainer<tString>& aStringList, const tString&
aDelimiter)
{
tString lResult;
for(tString lPart : aStringList)
{
if(lResult.size() > 0)
lResult += aDelimiter;
lResult += lPart;
}
return lResult;
}
But it not works. My g++ is:
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
I learn that it should work from:
https://en.cppreference.com/w/cpp/language/template_parameters
Error is like this:
/home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Tests/Src/StringTest.cpp:
In member function ‘void StringTest::test7()’:
/home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Tests/Src/StringTest.cpp:126:76:
error: no matching function for call to
‘gJoin<std::vector<std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >,
std::__cxx11::string>(std::vector<std::__cxx11::basic_string<char> >&,
std::__cxx11::basic_string<char>)’
std::string lTest1A(gJoin<vector<string>, string>(lVector1,
string(" ")));
^
In file included from
/home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Tests/Src/StringTest.cpp:4:0:
/home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Include/EnergoKodTools2/Strings.h:148:9:
note: candidate: template<template<class> class tContainer, class
tString> tString ekt2::gJoin(const tContainer<tString>&, const tString&)
tString gJoin(const tContainer<tString>& aStringList, const tString&
aDelimiter)
^~~~~
/home/szyk/!-EnergoKod/!-Libs/EnergoKodTools2/Include/EnergoKodTools2/Strings.h:148:9:
note: template argument deduction/substitution failed:
Tests/CMakeFiles/EnergoKodTools2Test.dir/build.make:158: recipe for
target 'Tests/CMakeFiles/EnergoKodTools2Test.dir/Src/StringTest.cpp.o'
failed
make[2]: ***
[Tests/CMakeFiles/EnergoKodTools2Test.dir/Src/StringTest.cpp.o] Error 1
make[1]: *** [Tests/CMakeFiles/EnergoKodTools2Test.dir/all] Error 2
make: *** [all] Error 2
CMakeFiles/Makefile2:122: recipe for target
'Tests/CMakeFiles/EnergoKodTools2Test.dir/all' failed
Makefile:129: recipe for target 'all' failed
17:45:51: Proces "/usr/bin/cmake" zakończył się kodem wyjściowym 2.
Błąd budowania / instalowania projektu EnergoKodTools2 (zestaw narzędzi:
Desktop Qt 5.12.3 GCC 64bit2)
Podczas wykonywania kroku "Wersja CMake"
please help me,
best regards,
and thanks in advance
Szyk Cech