История изменений
Исправление dissident, (текущая версия) :
Template argument deduction requires exact matches
- https://stackoverflow.com/questions/25020680/automatic-conversion-of-function-arguments-between-related-template-classes
- https://stackoverflow.com/questions/45765205/template-function-argument-deduction-with-an-implicit-conversion
Т.е. вот так можно:
#include <iostream>
using namespace std;
template<typename CharT> class my_char_traits {};
template<typename CharT> class my_allocator {};
template
<
typename CharT,
class MyTraits = my_char_traits<CharT>,
class MyAllocator = my_allocator<CharT>
>
class my_basic_string {
public:
my_basic_string(const char*) { /* Do nothing */ }
};
class MyLocale
{
public:
template
<
typename CharT,
template <typename> class MyTraits = my_char_traits,
template <typename> class MyAllocator = my_allocator
>
bool operator()( const my_basic_string<CharT,MyTraits<CharT>,MyAllocator<CharT>>& s1,
const my_basic_string<CharT,MyTraits<CharT>,MyAllocator<CharT>>& s2) const
{
return true;
}
};
int main(int argc, char* argv[])
{
my_basic_string<char> a1("keke");
my_basic_string<char> a2("keke");
cout << MyLocale(a1, a2) << endl;
// cout << MyLocale().operator()<char>("kekeke", "kekeke") << endl;
}
А вот то, что закоментировано внизу уже нельзя. :-|
Исправление dissident, :
Template argument deduction requires exact matches
- https://stackoverflow.com/questions/25020680/automatic-conversion-of-function-arguments-between-related-template-classes
- https://stackoverflow.com/questions/45765205/template-function-argument-deduction-with-an-implicit-conversion
Т.е. вот так можно:
#include <iostream>
using namespace std;
template<typename CharT> class my_char_traits {};
template<typename CharT> class my_allocator {};
template
<
typename CharT,
class MyTraits = my_char_traits<CharT>,
class MyAllocator = my_allocator<CharT>
>
class my_basic_string {
public:
my_basic_string(const char*) { /* Do nothing */ }
};
class MyLocale
{
public:
template
<
typename CharT,
template <typename> class MyTraits = my_char_traits,
template <typename> class MyAllocator = my_allocator
>
bool operator()( const my_basic_string<CharT,MyTraits<CharT>,MyAllocator<CharT>>& s1,
const my_basic_string<CharT,MyTraits<CharT>,MyAllocator<CharT>>& s2) const
{
return true;
}
};
int main(int argc, char* argv[])
{
my_basic_string<char> a1("keke");
my_basic_string<char> a2("keke");
cout << MyLocale().operator()<char>(a1, a2) << endl;
// cout << MyLocale().operator()<char>("kekeke", "kekeke") << endl;
}
А вот то, что закоментировано внизу уже нельзя.
Исходная версия dissident, :
Template argument deduction requires exact matches
Т.е. вот так можно:
#include <iostream>
using namespace std;
template<typename CharT> class my_char_traits {};
template<typename CharT> class my_allocator {};
template
<
typename CharT,
class MyTraits = my_char_traits<CharT>,
class MyAllocator = my_allocator<CharT>
>
class my_basic_string {
public:
my_basic_string(const char*) { /* Do nothing */ }
};
class MyLocale
{
public:
template
<
typename CharT,
template <typename> class MyTraits = my_char_traits,
template <typename> class MyAllocator = my_allocator
>
bool operator()( const my_basic_string<CharT,MyTraits<CharT>,MyAllocator<CharT>>& s1,
const my_basic_string<CharT,MyTraits<CharT>,MyAllocator<CharT>>& s2) const
{
return true;
}
};
int main(int argc, char* argv[])
{
my_basic_string<char> a1("keke");
my_basic_string<char> a2("keke");
cout << MyLocale().operator()<char>(a1, a2) << endl;
// cout << MyLocale().operator()<char>("kekeke", "kekeke") << endl;
}
А вот то, что закоментировано внизу уже нельзя.