Boost logo

Boost :

From: Ehsan Akhgari (ehsan_at_[hidden])
Date: 2003-08-31 10:06:31


Hi all,

I have written a relatively small library which I've found pretty useful
in my own projects. I have to deal with std::basic_string objects a lot
in my applications, and I almost always write template code so that the
same code works with both std::string and std::wstring types. The only
problem which cannot be directly solved with existing language construct
is handling string literals.

To make myself clear, the below code will only work for f< char >():

 template < typename char_type >
 void f()
 {
  std::basic_string< char_type > str( "hello" );
 }

What is needed here is some facility which selects either "hello" or
L"hello" based upon char_type. Now, using my library, the above code
can be fixed like this:

 template < typename char_type >
 void g()
 {
  std::basic_string< char_type > str( TextAutoSelect( char_type, "hello"
) );
 }

Nearly all the job is done at compile-time, and the only runtime cost
would be that of a one-line inline function (which can be optimized away
using compiler optimizations, like the VC++ compiler does.)

I would like to know if there is any interest for this tiny library to
be submitted to Boost.

Thanks for your consideration,
-------------
Ehsan Akhgari

List Owner: MSVC_at_[hidden]

[ Email: ehsan_at_[hidden] ]
[ WWW: http://www.beginthread.com/Ehsan ]


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