Boost logo

Boost Users :

From: ravioli_at_[hidden]
Date: 2002-05-22 17:59:17


Would it be possible to use an existing conversion operator ?
Example :
class Output {
 ...
}

class Input {
    operator Output(void) [ return ... ; }
}

Then :
lexical_cast<Output>( Input )
... would use this conversion operator.

This article
http://www.cuj.com/experts/1810/alexandr.htm?topic=experts

... describes hox it is possible at compile-time to detect whether a class A is convertible to class B,
ie if an operator already exists. If so, we would not need in lexical_cast<> to use the serialization operation.

What also would be great, is to specialise lexical_cast<> for conversion where is very fast builtin function or operator already exists.

  ----- Original Message -----
  From: Terje Slettebų
  To: Boost-Users_at_[hidden]
  Sent: Wednesday, May 22, 2002 10:46 PM
  Subject: RE: [Boost-Users] boost::lexical_cast string to string problem - New proposition available

>--- In Boost-Users_at_y..., Tom Matelich <tmatelich_at_z...> wrote:
> I and many others have requested fixes for this for a very long time.
> Basically, it involves creating class templates to do the actual
  conversion.
> It's not the most complicated system, just nobody has done it yet. If you
> search the boost list archives, you'll see a lot of mail about this.
  There
> is no quick solution to your problem though.

  I've searched the archive, now, and see that there's been quite a few
  propositions for changes, but apparently none of them have ended up in the
  lexical_cast implementation.

  There's also a couple of propositions, here
  (http://groups.yahoo.com/group/boost/files/lexical_cast_propositions/).

  Some of the proposed changes are:

  - wlexical_cast - A version that can use wide characters
  - basic_lexical_cast - A version that takes the interpreter (stringstream)
  as a parameter, to support things like changing locale
  - Being able to set number base (dec, oct or hex). This would be implicitly
  possible using basic_lexical_cast
  - Being able to set precision for numerical conversions. This may also be
  done with basic_lexical_cast
  - Checking for change of sign, when using unsigned numbers. This is
  addressed using an integer adapter, in the above lexical_cast_propositions

  One problem with doing these changes, after having talked with Kevlin Henney
  a while ago (without knowing it had been already proposed, I proposed an
  extra parameter, for setting the number base). is that he prefers to not
  have extra parameters in the interface, as it then will no longer look like
  a cast, and it may be less generic, depending on the way it's done. For
  example, a base-setting argument wouldn't make much sense if you converted
  from floating point to string.

  In any case, I have actually just now made a version of lexical_cast, that
  fixes the problem pointed out by OP, here, and I've made it available in the
  Boost files section
  (http://groups.yahoo.com/group/boost/files/lexical_cast_proposition/). I've
  also put a unit test for it, there. Feedback is welcome.

  It doesn't change the interface in any way, so it should be ok.

  The new version supports conversion between string and char, including char
  containing whitespace, and when the string is empty, or containing only
  whitespace.

  If the source or destination (or both) is basic_string or char/wchar_t, it
  will set the interpreter to use the char type used, so it implicitely
  supports wide characters. Wide character support requires partial
  specialisation if one of the operands is not either basic_string or
  char/wchar_t.

  In the case where the source is basic_string, it also uses pass by const
  reference, for efficiency.

  It's tested on Intel C++ 6.0, MSVC 6.0 and BCC 5.6.

  Regards,

  Terje

        Yahoo! Groups Sponsor
              ADVERTISEMENT
             
       
       

  Info: <http://www.boost.org>
  Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
  Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>

  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

[Non-text portions of this message have been removed]


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