Keep the const char pointers
###Keep the const char pointers
II agree with Lokis proposed changes, except that I would leave delimiter
and real_delim
as charT const *
and change the constructor to:
infix_ostream_iterator(ostream_type &s, charT const *d = 0)
: os(&s)
, delimiter("")
, real_delim(d ? d : "")
{
}
That way we reduce the cost of copying the strings, instead we just copy a pointer.
Deduced types
###Deduced types
MimickingMimicking the changes made to std::less in C++14, you could make operator=
a template, that way we don't need to specify this type for the class. This would though break the compatibility with the std::ostream_iterator
interface.
template <class T>
infix_ostream_iterator<charT, traits> &operator=(T const &item)
{
*os << delimiter << item;
delimiter = real_delim;
return *this;
}
###Keep the const char pointers
I agree with Lokis proposed changes, except that I would leave delimiter
and real_delim
as charT const *
and change the constructor to:
infix_ostream_iterator(ostream_type &s, charT const *d = 0)
: os(&s)
, delimiter("")
, real_delim(d ? d : "")
{
}
That way we reduce the cost of copying the strings, instead we just copy a pointer.
###Deduced types
Mimicking the changes made to std::less in C++14, you could make operator=
a template, that way we don't need to specify this type for the class. This would though break the compatibility with the std::ostream_iterator
interface.
template <class T>
infix_ostream_iterator<charT, traits> &operator=(T const &item)
{
*os << delimiter << item;
delimiter = real_delim;
return *this;
}
Keep the const char pointers
I agree with Lokis proposed changes, except that I would leave delimiter
and real_delim
as charT const *
and change the constructor to:
infix_ostream_iterator(ostream_type &s, charT const *d = 0)
: os(&s)
, delimiter("")
, real_delim(d ? d : "")
{
}
That way we reduce the cost of copying the strings, instead we just copy a pointer.
Deduced types
Mimicking the changes made to std::less in C++14, you could make operator=
a template, that way we don't need to specify this type for the class. This would though break the compatibility with the std::ostream_iterator
interface.
template <class T>
infix_ostream_iterator<charT, traits> &operator=(T const &item)
{
*os << delimiter << item;
delimiter = real_delim;
return *this;
}
###Keep the const char pointers
I agree with Lokis proposed changes, except that I would leave delimiter
and real_delim
as charT const *
and change the constructor to:
infix_ostream_iterator(ostream_type &s, charT const *d = 0)
: os(&s)
, delimiter("")
, real_delim(d ? d : "")
{
}
That way we reduce the cost of copying the strings, instead we just copy a pointer.
###Deduced types
Mimicking the changes made to std::less in C++14, you could make operator=
a template, that way we don't need to specify this type for the class. This would though break the compatibility with the std::ostream_iterator
interface.
template <class T>
infix_ostream_iterator<charT, traits> &operator=(T const &item)
{
*os << delimiter << item;
delimiter = real_delim;
return *this;
}