On 02/07/07, Andrew Sayers <andrew-mysqlpp@stripped> wrote:
>
> +inline std::ostream& operator <<(quote_type1 o,
> + char in[])
> +{
> + return operator <<(o, static_cast<const char* const&>(in));
> +}
Personally I would use simply static_cast<cont char*>(in) if doing that.
It is a direct conversion from char[] to char* and last time I saw any
benchmarks it was cheaper to copy a pointer a reference (and it will
be copied by value when passed to the operator<< function anyway.) The
assembly code shows five instructions for the reference version and
two otherwise.
Alternatively, something like
template <int N>
inline std::ostream& operator <<(quote_type1 o, const char (&in)[N])
{
return o.ostr->write(in, N-1); // don't write nul terminator
}
You know the size of the array, why discard that info and require a strlen call?
The const overloads aren't needed, char[N] will match const char[N]
rather than the default specialisation, so you only need one overload
for quote_type1 and one for escape_type1.
Jon