C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

testing object streamability

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
tony_in_da_uk@yahoo.co.uk
Guest





PostPosted: Wed Jul 27, 2005 11:10 pm    Post subject: testing object streamability Reply with quote



Hi people,

I was just wondering what other people have done when they wanted to
test for the streamability of an object, and if anyone's interested
enough to try my code (attached) - hoping they might report something
about the portability. I've only used it on Solaris with GNU g++ 4.0.1
and Sun CC 5.8.

Thanks in advance,

Tony

[[ Class names changed for my childish amusement. If nobody else has a
better implementation, then full bragging rights reserved ;-P. FWIW,
the problem's a bit harder than testing for other member functions
because operator<<(X&, ...) won't compile. For anyone confused, it's
all about order of matching - much as I hate to refer anyone to an MS
site, useful information does exist at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/overl_5.asp
]]



namespace Weird
{
// a fallback for when no other operator<< is available
class Donkey;

struct Snake
{
template Snake(const T&) { }
};

void operator<<(Donkey*, const Snake&)
{
// to get here:
// - Monkey_Stream implicitly converted to Donkey*
// - streamed type implicitly constructed Snake
// - found operator<< by Koenig lookup on stream
// this appears to be just enough obscurity to
// disambiguate other operator<<()s, but just
// enough of a connection to be findable
}

class Monkey_Stream : public std::ostringstream
{
public:
operator Donkey*() { return 0; }
};
}

// Sample usage:

// save(expr) returns the expressions value while
// preserving its streamed representation iff available
class Saver
{
public:
template const T& save(const T& t)
{
oss_ << t;
return t;
}

string str() const { return oss_.str(); }

private:
Weird::Monkey_Stream oss_;
};


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Maxim Yegorushkin
Guest





PostPosted: Thu Jul 28, 2005 11:21 am    Post subject: Re: testing object streamability Reply with quote



[email]tony_in_da_uk (AT) yahoo (DOT) co.uk[/email] wrote:

Quote:
I was just wondering what other people have done when they wanted to
test for the streamability of an object, and if anyone's interested
enough to try my code (attached) - hoping they might report something
about the portability. I've only used it on Solaris with GNU g++ 4.0.1
and Sun CC 5.8.

They've been doing it like this:
http://groups-beta.google.com/group/comp.lang.c++.moderated/msg/8235a058359911dc


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.