Boost Libc++ Issue/Question
Michael Dickens
michaelld at macports.org
Fri Nov 1 20:50:50 PDT 2013
I have a ticket < https://trac.macports.org/ticket/41004 > with an issue
between Boost and Apple's new libc++; or, something like that. A simple
program which shows this issue is:
{{{
#include <boost/lexical_cast.hpp>
template <class T> struct to_hex{
T value;
operator T() const {return value;}
friend std::istream& operator>>(std::istream& lhs, to_hex& rhs){
lhs >> std::hex >> rhs.value;
return lhs;
}
};
int main() {
std::string ss("0x192");
boost::uint16_t foo = boost::lexical_cast<to_hex<boost::uint16_t>
>(ss);
return 0;
};
}}}
The above compiles (and executes) with:
{{{
clang++ -c -stdlib=libstdc++ -Wall -I/opt/local/include -o
test_boost_lexical_cast.o test_boost_lexical_cast.cpp
}}}
but not if "-stdlib=libc++". The error is
"/opt/local/include/boost/type_traits/detail/has_binary_operator.hpp:157:68:
error: use of overloaded operator '>>' is ambiguous (with operand types
'std::__1::basic_istream<wchar_t>' and 'to_hex<unsigned short>')".
While I can change the whole boost::lexical_cast to instead be:
{{{
std::stringstream interpreter(ss);
to_hex<boost::uint16_t> hh;
interpreter >> hh;
boost::uint16_t foo = hh;
}}}
that is sloppy; I like the neatness of the lexical_cast. That said, I'm
open to other's suggestions of alternative implementations -- converting
a hex-style numeric string ("0x[0-9a-zA-Z]*") into a uint16.
There is a boost ticket < https://svn.boost.org/trac/boost/ticket/6219 >
which is similar but not this; I have not found a reason or solution in
all of my searching, hence the query to this erudite list! I value your
thoughts ... - MLD
More information about the macports-dev
mailing list