Re: [boost] Proposal: static_string library

2003-03-06 Thread Terje Slettebø
>From: "Beman Dawes" <[EMAIL PROTECTED]>

> At 05:58 PM 3/5/2003, Robert Klarer wrote:
>
>  >The purpose of the static_string library is to offer an alternative to
>  >string literals and the standard type const std::string.  A
>  >static_string uses no dynamically allocated memory, and is more
>  >efficient at execution time than either string literals or
>  >basic_strings.
>
> Yes, agreed. That would be useful. IIRC, the C++ committee's performance
> working groups has talked about such a string in the past.
>
> There are questions that come to mind:
>
> * Can you come up with a small, workable language extension that eases
> those problems?

Josuttis/Vandevoorde mentions being able to pass string literals as template
parameters as a possible future extension. That would be a clean way to
handle it. Possibly could there also be a general solution regarding passing
compound values. At the moment, values of class type can't be passed as
template parameters.

> * Can you come up with an alternate design that gives up a tiny bit of
> efficiency (one pointer indirection perhaps) but then allows reasonable
> construction and internationalization?

If run-time computation is ok, and that one only wants to avoid dynamical
allocation, then one might do something like I used in another posting in
this thread:

template
class fixed_size_string;

template
fixed_size_string operator+(const
fixed_size_string &s1, const fixed_size_string
&s2);

etc.


Regards,

Terje

___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Proposal: static_string library

2003-03-06 Thread David Abrahams
Beman Dawes <[EMAIL PROTECTED]> writes:

> Lack of internationalization support is also a serious concern.

What would internationalization support look like on a static string?!

> There are questions that come to mind:
>
> * Can you come up with a small, workable language extension that eases
>   those problems?
>
> * Can you come up with an alternate design that gives up a tiny bit of
>   efficiency (one pointer indirection perhaps) but then allows
>   reasonable construction and internationalization?

That's potentially a huge difference.  With a truly static string you
can do computations at compile-time.

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

___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Re: [boost] Proposal: static_string library

2003-03-06 Thread Beman Dawes
At 05:58 PM 3/5/2003, Robert Klarer wrote:

>There's already been some discussion of this library under the thread
>"Proposal: strings as template parameters," but static_string hasn't
>been the subject of its own thread, so I'm starting this one.  I'd like
>to solicit opinions about this project.  Is it worthwhile?
>
>The purpose of the static_string library is to offer an alternative to
>string literals and the standard type const std::string.  A
>static_string uses no dynamically allocated memory, and is more
>efficient at execution time than either string literals or
>basic_strings.
Yes, agreed. That would be useful. IIRC, the C++ committee's performance 
working groups has talked about such a string in the past.

But...

>The syntax for declaring a static_string is unfortunate...
>
>  boost::static_string<'s', 't', 'a', 't', 'i', 'c', '_'> StrType1;
Unfortunate? Is that one of those understatement jokes Canadians are known 
for? I'd say it is way worse that "unfortunate" - it is ugly and error 
prone.

Lack of internationalization support is also a serious concern.

There are questions that come to mind:

* Can you come up with a small, workable language extension that eases 
those problems?

* Can you come up with an alternate design that gives up a tiny bit of 
efficiency (one pointer indirection perhaps) but then allows reasonable 
construction and internationalization?

Wondering-out-loud,

--Beman

___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


[boost] Proposal: static_string library

2003-03-05 Thread Robert Klarer
There's already been some discussion of this library under the thread
"Proposal: strings as template parameters," but static_string hasn't
been the subject of its own thread, so I'm starting this one.  I'd like
to solicit opinions about this project.  Is it worthwhile?

The purpose of the static_string library is to offer an alternative to
string literals and the standard type const std::string.  A
static_string uses no dynamically allocated memory, and is more
efficient at execution time than either string literals or
basic_strings.

The syntax for declaring a static_string is unfortunate, but once it has
been declared, a static_string's interface is (almost*) the same as that
of a const std::string.

* A static_string does not allocate memory, so it has no allocator_type.
Similarly, since a static_string can only be used with characters of
type char, no traits_type is necessary.

//Example 1: declaring and using a static_string
//
#include 

int main()
{
   typedef boost::static_string<'s', 't', 'a', 't', 'i', 'c', '_'>
StrType1;

   StrType1 str1;

   std::cout << "string one is: \'" << str1 << "\'\n";
   std::cout << "length of string one is: " << str1.length() << '\n';

   std::cout << "remove \'a\': ";
   std::ostream_iterator oi(std::cout);
   std::remove_copy(str1.begin(), str1.end(), oi, 'a'); // prints
"sttic_"
   std::cout << std::endl;
}

A static_string cannot be modified, so all of the iterator types nested
within static_string behave as const_iterators.  Internally, these
iterators are represented using pointers to const char, and are
therefore random access iterators.

Since the contents of a static_string are known at compile time, many
operations involving static_strings can be computed at program compile
time so that they are essentially free at program execution time
(assuming inlining).


//Example 2: free lunch?
//
#include 
#include 

int main()
{
   typedef boost::static_string<'s', 't', 'a', 't', 'i', 'c', '_'>
StrType1;
   typedef boost::static_string<'s', 't', 'r', 'i', 'n', 'g'> StrType2;

   StrType1 str1;
   StrType2 str2;

   std::cout << "Strings one and two are "
 << (str1.compare(str2) ? "not " : "") // cost of this call
is nil
 << "equal" << std::endl;
}

As well, number of metafunctions are defined for static_string.  Any
operation that be performed by means of a call to one of static_string's
member functions can be performed by one of these metafunctions.


//Example 3: metafunction interface
//
#include 
#include 

int main()
{
   typedef boost::static_string<'s', 't', 'a', 't', 'i', 'c', '_'>
StrType1;
   typedef boost::static_string<'s', 't', 'r', 'i', 'n', 'g'> StrType2;

   typedef StrType1::concat_static::apply::value StrType3;
   std::cout << "Concatenation of strings one and two: "
 << StrType3::c_str_static::apply::value
 << std::endl;
}

Thanks for considering my proposal.


___
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost