|
Boost : |
From: Reece Dunn (msclrhd_at_[hidden])
Date: 2006-01-31 03:59:25
Martin wrote:
>I found it useful when working with C APIs.
>
>With a fixed_string type I can do:
>
>boost::fixed_string<30> str;
>someoldcapi(str.buffer());
>str.find(...)
>
>instead of first using a char array and then copy it to a basic_string.
>
>Second use for me is to have a basic_string compatible buffer to use in
>shared
>memory/IPC.
Don't you mean char[] compatible buffer? Yes... the current version has
broken that, but I now know how to rework it so that this should work
properly:
>struct commandlineargs {
> boost::fixed_string<20> arg1;
> boost::filesystem::basic_path<boost::fixed_string<256> > path1
>};
>
>Unfortuntaly the review version of the fixed_string doesn't work with any
>of
>the above cases (first case needs a setlength() call).
In the new version, buffer() will return an object that will recalculate the
string size when it is destroyed, so you won't need to call setlength(). I
will provide a bufferex() or raw_buffer() that won't update the length, so
you could have:
fixed_string< 100 > str;
some_fn( str.buffer());
some_fn2( str.raw_buffer(), str.length_calculator());
str.setlength( some_fn2( str.raw_buffer()));
depending on the prototype of the function.
>overrun protection isn't important for me.
Ok.
- Reece
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk