Boost logo

Boost Users :

From: Terje Slettebų (tslettebo_at_[hidden])
Date: 2005-01-31 14:07:06

>From: "Yuval Ronen" <ronen_yuval_at_[hidden]>

> > Come to think of it, it can be done simpler and clearer, and avoiding
> > extra includes, like this:
> >
> > namespace detail
> > {
> > template<class T>
> > struct array_to_pointer_decay
> > {
> > typedef T type;
> > };
> >
> > template<class T, size_t N>
> > struct array_to_pointer_decay<T[N]>
> > {
> > typedef const T * type;
> > };
> > }
> >
> > template<typename Target, typename Source>
> > Target lexical_cast(const Source &arg)
> > {
> > typedef typename detail::array_to_pointer_decay<Source>::type
> > NewSource;
> >
> > detail::lexical_stream<Target, NewSource> interpreter;
> > Target result;
> >
> > if(!(interpreter << arg && interpreter >> result))
> > throw_exception(bad_lexical_cast(typeid(NewSource),
> > typeid(Target)));
> > return result;
> > }
> I haven't tried it, but I have a feeling that it will work for string
> literals, but not for c-string variables

With "c-string variables", do you mean pointer to char? Or something like
MFC's CString?

Anyway, the first is supported as before. The above just ensures that the
type passed to the rest of lexical_cast is the same type it used to be, when
it used pass by value. So arrays will decay to pointers, and everything else
will pass through unaltered. I ran the above through the unit test, and it
passes all, on the three compilers I tested it with. I've since talked with
Kevlin, and this was also what he had in mind, to make pass by const
reference work.

> > This requires support for partial specialisation, but so does
> > used in the first suggestion, so it doesn't change the compiler
> > requirements. Besides, the current version of lexical_cast in CVS
> > work with MSVC 6, anyway. Of course, if this was very important, I guess
> > would be possible to fall back to pass by value for MSVC 6, and possibly
> > other problems with it. I also see that MSVC 6 is no longer part of the
> > Boost regression test.
> Do you mean that boost has finally dropped support for MSVC 6?

Well, eh, not really. :) I asked about this on the developer list, and got
this reply:

--- Start quote ---

From: "Jeff Garland" <jeff_at_[hidden]>
To: <boost_at_[hidden]>; <boost_at_[hidden]>
Sent: Sunday, January 30, 2005 7:33 PM
Subject: Re: [boost] lexical_cast: Needing to work for MSVC 6 (and similar)?

On Sun, 30 Jan 2005 17:55:55 +0100, Terje Slettebų wrote

> Because of this, Kevlin Henney and I was wondering whether or
> not MSVC 6 support for this component (and components in Boost in
> general) is no longer demanded, or in general, what the required
> conformance level is?

We've discussed this a number of times, but there is no 'boost-wide' policy.
Some libraries have slowly started dropping VC6 support -- spirit comes to
mind. Some authors (as I recall the Boost.Python folks) have a strong user
base still using VC6 and don't want to cut it off. With date-time I've been
taking the approach of attempting to maintain existing functionality, but
functionality that breaks VC6 is essentially simply marked. Even
existing functions takes significant effort because of the VC6 fragilities.
For example, someone recently reported that VC6 with STLPort and date-time
creates an ICE.

Personally, I think the time has come to cut the cord on VC6 testing and
compatibility. In my mind Boost as a whole is being held back by the time
Boost developers waste hacking apart their implementations and answering
questions for this 7 year old, seriously non-compliant compiler. Perhaps
fact that we move on will spur some people to upgrade compilers, improving
life of a few c++ developers along the way (I suppose this also might
sales in Redmond -- of course they already mention Boost on the VC7
packaging...). And the folks stuck with VC6 can always use older versions
Boost or test out new versions against VC6 for themselves, submit patches,
pay someone to do this work.

BTW, I have an interest in your decision b/c date-time depends on
lexical_cast. So far whatever is breaking the regression tests doesn't seem
to be affecting date-time...


--- End quote ---

However, since lexical_cast is such a simple component, and that - like it
or not - it seems that quite a few people are still using MSVC 6 at work
(possibly due to the codebase not handling a newer compiler...), it would be
a shame not to make it available for them, as well. Therefore, we'll use the
code above (which requires partial specialisation), and supply
preprocessor-switched workaround-code for compilers lacking PTS, using full

> Congratulations, it's about time... :-)

I wish... :) One problem is that it's only a couple of years since MSVC 7.1
came, and even though MSVC 6 is old, 7.1 was the first version with PTS. So
we might have to live with 6.0 a little longer. At least for existing

> Anyway, the above solution looks excellent to me.

Thanks. :)



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at