[lexical_cast] Some code that was compiling in 1.50 stopped compiling in 1.53

Here's some code that has been compiling till at least 1.50, and starting long before. I isolated the part that breaks to create a program. Here it is: Just taking a std::vector of int and copying into strings. #include <boost/lexical_cast.hpp> #include <vector> #include <string> using namespace std; int main (int, char **) { vector<int> values; vector<string> ret; std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>); } And compiling on fedora 18, gcc 4.7 (Got same issues, I believe, with MSVC 10) I get the output at the bottom. Anyone has an idea on what the problem could be? Thanks, a [aleblanc@localhost base]$ gcc -c TestLexicalCast.cc [aleblanc@localhost base]$ gcc -c -I/home/aleblanc/local/boost_1_53/include/ TestLexicalCast.cc TestLexicalCast.cc: In function ‘int main(int, char**)’: TestLexicalCast.cc:10:98: error: no matching function for call to ‘transform(std::vector<int>::iterator, std::vector<int>::iterator, std::vector<std::basic_string<char> >::iterator, <unresolved overloaded function type>)’ TestLexicalCast.cc:10:98: note: candidates are: In file included from /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/algorithm:63:0, from /home/aleblanc/local/boost_1_53/include/boost/utility/swap.hpp:24, from /home/aleblanc/local/boost_1_53/include/boost/swap.hpp:10, from /home/aleblanc/local/boost_1_53/include/boost/array.hpp:45, from /home/aleblanc/local/boost_1_53/include/boost/lexical_cast.hpp:158, from TestLexicalCast.cc:1: /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_algo.h:4940:5: note: template<class _IIter, class _OIter, class _UnaryOperation> _OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_algo.h:4940:5: note: template argument deduction/substitution failed: TestLexicalCast.cc:10:98: note: could not resolve address from overloaded function ‘lexical_cast<std::string, int>’ In file included from /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/algorithm:63:0, from /home/aleblanc/local/boost_1_53/include/boost/utility/swap.hpp:24, from /home/aleblanc/local/boost_1_53/include/boost/swap.hpp:10, from /home/aleblanc/local/boost_1_53/include/boost/array.hpp:45, from /home/aleblanc/local/boost_1_53/include/boost/lexical_cast.hpp:158, from TestLexicalCast.cc:1: /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_algo.h:4977:5: note: template<class _IIter1, class _IIter2, class _OIter, class _BinaryOperation> _OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter, _BinaryOperation) /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_algo.h:4977:5: note: template argument deduction/substitution failed: TestLexicalCast.cc:10:98: note: could not resolve address from overloaded function ‘lexical_cast<std::string, int>’ [aleblanc@localhost base]$

2013/3/15 Alain Leblanc <aalebl@gmail.com>:
Here's some code that has been compiling till at least 1.50, and starting long before. I isolated the part that breaks to create a program.
Here it is: Just taking a std::vector of int and copying into strings.
#include <boost/lexical_cast.hpp> #include <vector> #include <string>
using namespace std;
int main (int, char **) { vector<int> values; vector<string> ret; std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>); }
That is strange, I remember fixing that... I'll check everything once more. Until then, you may try this workaround: int main (int, char **) { vector<int> values; vector<string> ret; typedef std::string(*f2)(const int&); f2 p2 = &boost::lexical_cast<std::string, int>; std::transform(values.begin(), values.end(), ret.begin(), p2); } -- Best regards, Antony Polukhin

2013/3/16 Antony Polukhin <antoshkka@gmail.com>:
2013/3/15 Alain Leblanc <aalebl@gmail.com>:
Here's some code that has been compiling till at least 1.50, and starting long before. I isolated the part that breaks to create a program.
Here it is: Just taking a std::vector of int and copying into strings.
#include <boost/lexical_cast.hpp> #include <vector> #include <string>
using namespace std;
int main (int, char **) { vector<int> values; vector<string> ret; std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>); }
That is strange, I remember fixing that... I'll check everything once more.
You were right, I've accidentally removed the fix in one of the commits (fixed it in trunk). You may use solution poposed in previous letter, take lexical_cast from boost trunk http://svn.boost.org/svn/boost/trunk/ or just replace in boost/lexical_cast.hpp following code: template <typename Target, typename CharType> inline Target lexical_cast(const CharType* chars, std::size_t count) { BOOST_STATIC_ASSERT_MSG(boost::detail::is_char_or_wchar<CharType>::value, "CharType must be a character or wide character type"); return boost::lexical_cast<Target>( boost::iterator_range<const CharType*>(chars, chars + count) ); } with template <typename Target> inline Target lexical_cast(const char* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const char*>(chars, chars + count) ); } template <typename Target> inline Target lexical_cast(const unsigned char* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const unsigned char*>(chars, chars + count) ); } template <typename Target> inline Target lexical_cast(const signed char* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const signed char*>(chars, chars + count) ); } #ifndef BOOST_LCAST_NO_WCHAR_T template <typename Target> inline Target lexical_cast(const wchar_t* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const wchar_t*>(chars, chars + count) ); } #endif #ifndef BOOST_NO_CHAR16_T template <typename Target> inline Target lexical_cast(const char16_t* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const char16_t*>(chars, chars + count) ); } #endif #ifndef BOOST_NO_CHAR32_T template <typename Target> inline Target lexical_cast(const char32_t* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const char32_t*>(chars, chars + count) ); } #endif -- Best regards, Antony Polukhin

2013/3/16 Antony Polukhin <antoshkka@gmail.com>
2013/3/16 Antony Polukhin <antoshkka@gmail.com>:
2013/3/15 Alain Leblanc <aalebl@gmail.com>:
Here's some code that has been compiling till at least 1.50, and starting long before. I isolated the part that breaks to create a program.
Here it is: Just taking a std::vector of int and copying into strings.
#include <boost/lexical_cast.hpp> #include <vector> #include <string>
using namespace std;
int main (int, char **) { vector<int> values; vector<string> ret; std::transform(values.begin(), values.end(), ret.begin(), boost::lexical_cast<std::string, int>); }
That is strange, I remember fixing that... I'll check everything once more.
You were right, I've accidentally removed the fix in one of the commits (fixed it in trunk). You may use solution poposed in previous letter, take lexical_cast from boost trunk http://svn.boost.org/svn/boost/trunk/ or just replace in boost/lexical_cast.hpp following code:
template <typename Target, typename CharType> inline Target lexical_cast(const CharType* chars, std::size_t count) {
BOOST_STATIC_ASSERT_MSG(boost::detail::is_char_or_wchar<CharType>::value, "CharType must be a character or wide character type");
return boost::lexical_cast<Target>( boost::iterator_range<const CharType*>(chars, chars + count) ); }
with
template <typename Target> inline Target lexical_cast(const char* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const char*>(chars, chars + count) ); }
template <typename Target> inline Target lexical_cast(const unsigned char* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const unsigned char*>(chars, chars + count) ); }
template <typename Target> inline Target lexical_cast(const signed char* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const signed char*>(chars, chars + count) ); }
#ifndef BOOST_LCAST_NO_WCHAR_T template <typename Target> inline Target lexical_cast(const wchar_t* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const wchar_t*>(chars, chars + count) ); } #endif #ifndef BOOST_NO_CHAR16_T template <typename Target> inline Target lexical_cast(const char16_t* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const char16_t*>(chars, chars + count) ); } #endif #ifndef BOOST_NO_CHAR32_T template <typename Target> inline Target lexical_cast(const char32_t* chars, std::size_t count) { return ::boost::lexical_cast<Target>( ::boost::iterator_range<const char32_t*>(chars, chars + count) ); } #endif
-- Best regards, Antony Polukhin _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Thanks Greg and Antony. I modified my code following Antony's suggestion and it works fine. a
participants (2)
-
Alain Leblanc
-
Antony Polukhin