From -3105075708311926496
X-Google-Thread: f78e5,ac8f7c796c0ee2eb
X-Google-Attributes: gidf78e5,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news3.google.com!out03a.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: Martin <wpcmame@hotmail.com>
Newsgroups: comp.std.c++
Subject: Re: std::pair istream >> operator
Date: Wed, 28 Nov 2007 11:55:57 CST
Organization: http://groups.google.com
Lines: 70
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <320d4cda-ad86-4c19-83ea-8c3fcc23e110@s36g2000prg.googlegroups.com>
References: <a7eb92bf-1ab8-438d-8bca-b6f7cfcc056c@o6g2000hsd.googlegroups.com> 
	<92a741eb-f9f2-40dc-b252-5f53a451af13@w34g2000hsg.googlegroups.com> 
	<84eb137f-aa46-443e-8f6a-912487da73ad@p69g2000hsa.googlegroups.com> 
	<MPG.21a93d925d61f8a989a9e@news.sunsite.dk> <c6dd44f5-b0eb-45ef-be8b-ee5d410ed626@e4g2000hsg.googlegroups.com> 
	<63447783-3e0d-41f8-98a6-62f69025e631@d50g2000hsf.googlegroups.com> 
	<d76955b6-a58b-4b1d-b9cb-ebf44907f8f0@e1g2000hsh.googlegroups.com> 
	<01a449b0-f514-44ff-9949-5a65d6e2dc46@w34g2000hsg.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1196244220 18508 127.0.0.1 (28 Nov 2007 10:03:40 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 28 Nov 2007 10:03:40 +0000 (UTC)
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
X-SMTP-Auth: no
Complaints-To: groups-abuse@google.com
Injection-Info: s36g2000prg.googlegroups.com; posting-host=62.95.16.58; 
	posting-account=6obM4goAAAAihX2IqW0281fEd31oVBnX
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) 
	Gecko/20070515 Firefox/2.0.0.4,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 fw.touchdown.se:8080 (squid/2.6.STABLE4)
Content-Disposition: inline
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Xref: g2news1.google.com comp.std.c++:9713

> The solution I'd always seen (in pre-standard complex) was to
> apply (width()-3)/2 to each of the components of the complex.

The draft standard says about stream::operator<<

Effects: inserts the complex number x onto the stream o as if it were
implemented as follows:
template<class T, class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& o, const complex<T>& x)
{
basic_ostringstream<charT, traits> s;
s.flags(o.flags());
s.imbue(o.getloc());
s.precision(o.precision());
s << '(' << x.real() << "," << x.imag() << ')';
return o << s.str();
}

>
> > If I could put in a recommendation it would be:
> > - Add a separator field to the ios_base structure (default =
> > traits::eof() -> ctype.isspace for input and space for output)
> > - Add manipulators: separator, setseparator, showseparator,
> > noshowseparator (default)
> > - Width, fill etc applies to each item (but not the separator)
> > - separator is also used to end stream input for string.
>
> None of which addresses the basic problem of outputting
> std::pair (or boost::tuple): the fact that the type may have
> different semantic signification at different places in the
> program.

Isn't that something that applies to all types?

Built in types like double got modifers on format, precision etc. If
you need some non-standard formatting you implement your own but it
still nice to have a default.

> Although there may be some special cases, my own feeling is that
> any use of std::pair (and probably most uses of boost::tuple)
> are simply poor programming.

I agree but admit I'm using them a lot. Specially in containers.

To make your own "named_tuple" you need to implement the operators as
well. I have some macros to do it but it quickly get inconvenient.

If I temporary need a set or map with 2 values inside a funtion I just
do a single line

typedef std::map<int, std::pair<std::string, int> > mymap;

To do it with a macro you first need to create the type outside the
function (template types need external linkage) which could be in .h
file somewhere.

NAMED_TUPLE(mytuple, std::string, name, int, value);
.

typedef std::map<int, mytuple> mymap;

It would be nice with a feature like the anonymous types in C# 3.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



