Gavin Doughtie on 15 Aug 2003 17:32:09 -0000 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [ALACPP] container streaming, sigh |
Hm, I was hoping to somehow bind directly to operator<< (though it won't have the endl I want). On Fri, Aug 15, 2003 at 10:27:01AM -0700, Jason Fredrickson wrote: > Well, I'd just create some global function, so: > > Namespace _Utility > { > void Serialize(ostream &lhs, const string &rhs) { > lhs << rhs << std::endl; } > } > > ostream& operator << (ostream& str, const vector<string> & rhs) { > for_each(rhs.begin(), rhs.end(), > boost::bind(&_Utility::Serialize, str, _1)); > return str; > } > > You still have the function, but you don't need all the reification > overhead - bind does that for you. > > Jason > > Jason Fredrickson > Vice-President, Operations > Agile Solutions > Jason.Fredrickson@xxxxxxxxxxxx > (626) 644-7280 > > > > > -----Original Message----- > > From: alacpp-bounces@xxxxxxxxxxx > > [mailto:alacpp-bounces@xxxxxxxxxxx] On Behalf Of Gavin Doughtie > > Sent: Friday, August 15, 2003 10:18 AM > > To: ALACPP Mailing List > > Subject: [ALACPP] container streaming, sigh > > > > > > ok, how about this. I want operator<<(ostream& str, > > vector<string> vals) > > > > This is my current implementation: > > > > class Outputter > > { > > public: > > Outputter(ostream& str) > > :mStr(str) {} > > > > ostream& operator()(const string &rhs) { > > return mStr << rhs << endl; > > } > > > > private: > > ostream& mStr; > > }; > > > > ostream& operator << (ostream& str, const vector<string> & rhs) { > > for_each(rhs.begin(), rhs.end(), Outputter(str)); > > return str; > > } > > > > But I think the whole Outputter class thingie can be ditched > > in favor of a clever bind, which I can't seem to get right. > > Volunteers? > > > > Gavin > > _______________________________________________ > > alacpp mailing list > > alacpp@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/alacpp > > > > > _______________________________________________ > alacpp mailing list > alacpp@xxxxxxxxxxx > http://lists.ellipsis.cx/mailman/listinfo/alacpp _______________________________________________ alacpp mailing list alacpp@xxxxxxxxxxx http://lists.ellipsis.cx/mailman/listinfo/alacpp