|
Boost : |
Subject: Re: [boost] [gsoc] Request Feedback for Boost.Ustr Unicode String Adapter
From: Soares Chen Ruo Fei (crf_at_[hidden])
Date: 2011-08-15 10:15:53
On Mon, Aug 15, 2011, Stewart, Robert wrote:
>> You're proposing a `text` class that is meant to somehow
>> overcome this problem. So you change the boost interface
>> to accept `text` but user code is left unchanged...:
>>
>> namespace boost { void func(const text& a); }
>> boost::func(non_utf_string); //oops, the std::string default
>> constructor is called.
>>
>> Yes, you can make this constructor explicit, so the above code
>> stops compiling and the user must write explicitly:
>> boost::func(text(non_utf_string));
>>
>> But then there is nothing in your proposal that makes
>> std::string utf-8 encoded by 'default'. Default == implicit.
>
> As soon as the client did a cast, the client made the claim that non_utf_string met the requirements of the text class' constructor. The problem is that of the client misusing the class by an ill-advised cast. What's more, I think Soares indicated a debug-build validation that the argument indeed was UTF-8.
For my design the programmer must explicitly choose an encoding in the
template instance and also explicitly call the constructor to
construct the Unicode string. As long as we make it hard enough that
programmer has to consciously call the constructor then the rest of
the responsibility will fall on the programmer. Remember, only prevent
accidental not intentional misusage.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk