Boost logo

Boost :

Subject: Re: [boost] [string] proposal
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-01-24 08:48:23


Dean Michael Berris wrote:
>
> Consider the following:
>
> template <class String>
> void needs_utf8(String const & s) {
> view<utf8_encoded> utf8_string(s);
> if (!valid(utf8_string))
> throw invalid_string("I need a UTF-8 string.");
> }
>
> template <class String>
> void needs_utf16(String const & s) {
> view<utf16_encoded> utf16_string(s);
> if (!valid(utf16_string))
> throw invalid_string("I need a UTF-16 string.");
> }
>
> I would say you have four choices when implementing `view`
> and `valid`:
>
> 1. view converts, and valid is a no-op.
> 2. view doesn't convert, and valid does the validation on the
> underlying string.
> 3. view converts, and valid does the validation on the
> underlying string.
> 4. view doesn't convert, but valid checks the validation on the view.
>
> I'm leaning towards #2.

#1 and #3 would be wasteful for cases when the string is already known to have the desired encoding, so they are non-starters.

I'm not sure I understand the distinction or reason for the distinction you imply by #2 versus #4. #2's wording suggests that you mean valid() accesses the underlying string through the view, but why is that better or worse than just using the view as in #4?

_____
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


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