
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Monday, August 06, 2012 1:22 PM To: boost@lists.boost.org Subject: Re: [boost] [type_erasure] Review started (July 18-27, 2012)
AMDG
On 08/06/2012 02:55 AM, Paul A. Bristow wrote:
template <typename K, typename T> std::ostream& operator<< (std::ostream& os, std::pair<K, T>& p) { /*! Output a pair of values. \details For example: "1.23 , 3.45". */ os << p.first << ", " << p.second; return os; }
And I can echo the input as expected
1, 9.9000 2, 8.8000
but when I try to use the sequence printer
p2.print(std::cout, my_map);
the compiler (VC10) complains the there is no operator<<
Yep. It can't be found by ADL unless it's declared in namespace std, which is forbidden. You can solve this by specializing boost::type_erasure::ostreamable instead,
I've confirmed that it works in the forbidden namespace std, but despite some splinters from head scratching, I have concluded that this is not in my skill set :-( This specialization of ostreamable: template<> struct ostreamable<class Os, const std::pair<const int, double>& > { static void apply(Os& out, const std::pair<const int, double>& arg) { out << arg; // No operator<< of type 'Os' } }; still doesn't resolve the requirement. type_erasure_print_map.cpp(140): error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'Os' (or there is no acceptable conversion) type_erasure_print_map.cpp(86): could be 'std::ostream &boost::type_erasure::operator <<<const int,double>(std::ostream &,const std::pair<_Ty1,_Ty2> &)' with [ _Ty1=const int, _Ty2=double ] type_erasure_print_map.cpp(96): or 'std::ostream &boost::type_erasure::operator <<(std::ostream &,const std::pair<_Ty1,_Ty2> &)' with [ _Ty1=const int, _Ty2=double ] while trying to match the argument list '(Os, const std::pair<_Ty1,_Ty2>)' with [ _Ty1=const int, _Ty2=double ] (Of course I really want the pairs types to be templated for types T1, and T2, but I thought I'd try to make it simpler to start). What am I still doing wrong? Thanks. Paul PS a full (not-)working example attached. --- Paul A. Bristow, Prizet Farmhouse, Kendal LA8 8AB UK +44 1539 561830 07714330204 pbristow@hetp.u-net.com