This has nothing to do with boost, strong_typedef or spirit.
It has a lot to do with type inference for template arguments. In short, when argument types are inferred, implicit conversions never occur [1]
Cf :.
#include <iostream> #include <string> #include <boost/strong_typedef.hpp> BOOST_STRONG_TYPEDEF(double, X) int main() { std::cout << X(); }
No problems! Replace double with std::string and it no longer works. What else?
The announcement of the streaming operator is different.
Contrast
ostream& ostream::operator<<(double);
To
template<typename _CharT, typename _Traits, typename _Alloc> inline basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>&, basic_string<_CharT, _Traits, _Alloc> const&)
The fact that operator overloading is a function template prohibits any implicit conversion.
[1] I suppose that initializer_list may seem a little exception here, with the extension / narrowing, what it can do. Another subject though
source share