List:MySQL++« Previous MessageNext Message »
From:Jonathan Wakely Date:July 4 2007 12:20am
Subject:Re: Bug: char[]s not escaped
View as plain text  
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.

Bug: char[]s not escapedAndrew Sayers2 Jul
  • Re: Bug: char[]s not escapedAndrew Sayers2 Jul
    • Re: Bug: char[]s not escapedWarren Young2 Jul
    • Re: Bug: char[]s not escapedJonathan Wakely4 Jul
      • Re: Bug: char[]s not escapedWarren Young6 Jul
        • Re: Bug: char[]s not escapedJonathan Wakely7 Jul