Я компилирую C++17 с кодом, подобным этому образцу:
#include <iostream>
#include <iterator>
class Foo {};
template <typename... Args,
typename ostream_type = ::std::basic_ostream<Args...>,
typename ostreambuf_iterator_type = ::std::ostreambuf_iterator<Args...>>
ostream_type &operator<<(ostream_type &os, const ::Foo f) {
// Do ostreambuf_iterator_type stuff with 'f' here...
return os;
}
int main() {
::Foo f;
::std::cout << f;
return 0;
}
Я обнаружил, что вывод типа шаблона терпит неудачу, когда я применяю Args...
к списку параметров шаблона как ostream_type
, так и ostreambuf_iterator_type
, но было бы хорошо, если бы я назначил char_type
и traits_type
из ostream_type
.
typename ostreambuf_iterator_type = ::std::ostreambuf_iterator<typename ostream_type::char_type, typename ostream_type::traits_type>>
Почему так, когда параметры шаблона на ::std::basic_ostream
и ::std::ostreambuf_iterator
одинаковы?