Listing 4

template< . . . >
C *fast_string_concatenator<S, C, T>::write(C *s) const
{
  return m_rhs.write(m_lhs.write(s));
}
template< . . . >
C *fast_string_concatenator<S, C, T>::Data::write(C *s) const
{
  size_t  len;
  switch(type)
  {
    case    seed:
      break;
    case    single:
      *(s++) = ref.ch;
      break;
    case    cstring:
      len = ref.cstring.len;
      memcpy(s, ref.cstring.s, sizeof(C) * len);
      s += len;
      break;
    case    concat:
      s = ref.concat->write(s);
      break;
  }
  return s;
}