[lexical_cast][trunk] problem with rev 41387 of boost/lexical_cast.hpp

Hello, the aforementioned revision adds a new Traits template parameter to boost::detail::lexical_stream, but it fails to accordingly upgrade the usage of lexical_stream at line 1183: template<typename Target, typename Source> Target lexical_cast(Source arg) { detail::lexical_stream<Target, Source> interpreter; Target result; ... Thank you, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Joaquín Mª López Muñoz <joaquin <at> tid.es> writes:
Hello, the aforementioned revision adds a new Traits template parameter to boost::detail::lexical_stream, but it fails to accordingly upgrade the usage of lexical_stream at line 1183:
template<typename Target, typename Source> Target lexical_cast(Source arg) { detail::lexical_stream<Target, Source> interpreter; Target result; ...
The comment above this function says: //call-by-value fallback version (deprecated) This branch is only for compilers with BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION defined. There is no support for non-standard traits for such compilers. -- Alexander

Alexander Nasonov ha escrito:
JoaquÃn Mª López Muñoz <joaquin <at> tid.es> writes:
Hello, the aforementioned revision adds a new Traits template parameter to boost::detail::lexical_stream, but it fails to accordingly upgrade the usage of lexical_stream at line 1183:
template<typename Target, typename Source> Target lexical_cast(Source arg) { detail::lexical_stream<Target, Source> interpreter; Target result; ...
The comment above this function says: //call-by-value fallback version (deprecated)
This branch is only for compilers with BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION defined. There is no support for non-standard traits for such compilers.
Hello Alexander, thanks for your quick response, The problem with rev 41387 is *not* that non-standard traits aren't supported for legacy compilers, but that lexical_cast is simply broken for such compilers, any code that used to use lexical_cast won't compile now , it's not about new features in boost::lexical_cast. Most notably, Boost.Test uses lexical_cast internally, so any lib that uses Boost.Test with a legacy compiler is now broken (this is actually my case.) Unless you want to ban every usage of lexical_cast in MSVC++ 6.0/7.0 and compilers without PTS, wouldn't be possible to provide some standard traits class in the usage of lexical_stream at line 1183 so as to not break legacy code? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Joaquín Mª López Muñoz <joaquin <at> tid.es> writes:
The problem with rev 41387 is *not* that non-standard traits aren't supported for legacy compilers, but that lexical_cast is simply broken for such compilers, any code that used to use lexical_cast won't compile now , it's not about new features in boost::lexical_cast.
I didn't realise it's broken. Can you please try this change? template<typename Target, typename Source> Target lexical_cast(Source arg) { typedef typename detail::widest_char< typename detail::stream_char<Target>::type , typename detail::stream_char<src>::type >::type char_type; typedef std::char_traits<char_type> traits; detail::lexical_stream<Target, Source, traits> interpreter; Target result; ... } Most notably, Boost.Test uses lexical_cast internally, so any lib that uses
Boost.Test with a legacy compiler is now broken (this is actually my case.)
I hate this dependency between Boost.Test and lexical_cast_test which is based on it.
Unless you want to ban every usage of lexical_cast in MSVC++ 6.0/7.0 and compilers without PTS, wouldn't be possible to provide some standard traits class in the usage of lexical_stream at line 1183 so as to not break legacy code?
Sure. If the code above won't work, you'll have to wait approx 12 hours for the fix. I don't have an access to old MSVC so I'm going to -DBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION and see what it breaks. -- Alexander

Alexander Nasonov <alnsn <at> yandex.ru> writes:
template<typename Target, typename Source> Target lexical_cast(Source arg) { typedef typename detail::widest_char< typename detail::stream_char<Target>::type , typename detail::stream_char<src>::type ^^^ Oops, copy/paste error. Please 's/src/Source/'. -- Alexander

Alexander Nasonov ha escrito:
Alexander Nasonov <alnsn <at> yandex.ru> writes:
template<typename Target, typename Source> Target lexical_cast(Source arg) { typedef typename detail::widest_char< typename detail::stream_char<Target>::type , typename detail::stream_char<src>::type ^^^ Oops, copy/paste error. Please 's/src/Source/'. --
The attached patch makes lexical_cast work again for MSVC++ 6.0. I can do the commit myself if you want. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Index: lexical_cast.hpp =================================================================== --- lexical_cast.hpp (revision 41392) +++ lexical_cast.hpp (working copy) @@ -1180,7 +1180,13 @@ template<typename Target, typename Source> Target lexical_cast(Source arg) { - detail::lexical_stream<Target, Source> interpreter; + typedef typename detail::widest_char< + BOOST_DEDUCED_TYPENAME detail::stream_char<Target>::type + , BOOST_DEDUCED_TYPENAME detail::stream_char<Source>::type + >::type char_type; + + typedef std::char_traits<char_type> traits; + detail::lexical_stream<Target, Source, traits> interpreter; Target result; if(!(interpreter << arg && interpreter >> result))
participants (2)
-
Alexander Nasonov
-
Joaquín Mª López Muñoz