Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-01-31 10:37:41


Martin <adrianm_at_[hidden]> writes:

> David Abrahams <dave <at> boost-consulting.com> writes:
>
>> "Paul A Bristow" <pbristow <at> hetp.u-net.com> writes:
>> > As another silent downloader, I just want to agree that we really do need a
>> > fixed_string,
>>
>> Why?
>>
>
> 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.

  std::string str(30, 0);
  someoldcapi(&str[0]);
  str.resize(str.find(0));
  str.find(...)

If we need a class to help with such a transition, we should design it
to make some of the operations more natural. But even that is not
probably worth the trouble.

> Second use for me is to have a basic_string compatible buffer to use in shared
> memory/IPC.
>
> struct commandlineargs {
> boost::fixed_string<20> arg1;
> boost::filesystem::basic_path<boost::fixed_string<256> > path1
> };

Isn't that what the allocator argument to basic_string is for?

> Unfortuntaly the review version of the fixed_string doesn't work
> with any of the above cases (first case needs a setlength() call).

Speaks volumes.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk