Boost logo

Boost :

From: Shane King (Shane_King_at_[hidden])
Date: 2002-04-07 18:20:49


Why is partial template specialisation needed to achieve this ... this
code seems to work for me (in VS6 & VS7):

template <class StringType, class InitialType>
StringType string_cast(const InitialType &initial)
{
        std::basic_ostringstream<
StringType::traits_type::char_type,
                                                StringType::traits_type,

        
StringType::allocator_type> os;
        os << initial;
        return os.str();
}

Which obviates the need for the compiler to support partial template
specialisation. Of course, PTS would be nice to allow narrow -> wide and
vice versa conversions.

-----Original Message-----
From: Mattias Flodin [mailto:flodin_at_[hidden]]
Sent: Saturday, 6 April 2002 5:54 PM
To: boost_at_[hidden]
Subject: Re: [boost] Proposal: string_cast

When you do, please try not to leave the Unicode question out of the
discussion. A separate name such as to_wstring seems insufficient to me
because
there are times when you cannot know beforehand whether the string type
you're
casting to is single-byte or Unicode (e.g. when writing generic code). I
have
posted a plausible solution (using partial specialization on the
contained
character type) before in
http://lists.boost.org/MailArchives/boost/msg27288.php


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