Boost logo

Boost Users :

From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2006-07-30 16:00:26


On 7/29/06, Edward Diener <eddielee_at_[hidden]> wrote:
>

[snipped]

>
> I once brought up this problem on comp.std.c++. Someone suggested, along
> the lines I was thinking, that C++ have a literal_cast<type>(literal
> expression) to cast a literal from one type to another using type
> notation. This would parallel the other C++ casts, such as static_cast
> and dynamic_cast.
>
> The notation L'char' ( and L"char-string" ), to cast from a narrow
> character ( character string ) to a wide character ( wide character
> string ) does not work nicely with templates as you have discovered,
> whereas a literal_cast<type>(expression) would do so, ie
> literal_cast<wchar_t>('char') ( or literal_cast<wstring>("char-string")
> ). In the literal_cast case, of course, one could use a character ( or
> string ) template type as the type passed to literal_cast and an
> equivalent narrow character or narrow string value, and always be
> guaranteed of the correct result.
>
> Of course literal_cast, if it existed, would work with any types which
> are currently represented as a literal in C++, but needless to say its
> main use would be to go from the C language L'' ( L"" ) notation to a
> notation that worked correctly and effortlessly in template code.
>
> However I have never written up such a suggestion to the C++ standard
> comittee. I still find the idea correct, however.

I believe that's really the best way to implement this functionality.
It would mimic lexical_cast interface too, which is already part of boost.

best regards,

-- 
Felipe Magno de Almeida

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net