
From: John Nagle <nagle@animats.com>
From: "Reece Dunn" <msclrhd@hotmail.com>
I am looking for a better solution to this. I am also thinking about how to remove the ABC from the implementation using a technique pointed out by someone on this thread (can't remember who):
class fs_base { size_t len; szie_t capacity; // needed for buffer-safe operations CharT str[ 1 ]; // string manipulation functions
fs_base( size_t c ): capacity( c ){} };
template< size_t n > class fixed_string: public fs_base { CharT data[ n ]; fixed_string(): fs_base( n ){} };
Are you assuming that "data[n]" physically follows "str[1]" in memory, and that "data[n]" can be addressed by subscripting "str[1]" out of range? That will work with most implementations, but it's not guaranteed to work. There are often intervening alignment bytes. Some debug implementations may place sentinel areas between objects to detect buffer overruns.
Oh, right. It was C99 that blessed the struct hack. Oh well. Maybe we could do it anyway on platforms where it's been proven to work? -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;