From -5422796068550675056
X-Google-Thread: f78e5,ac8f7c796c0ee2eb
X-Google-Attributes: gidf78e5,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news1.google.com!news.glorb.com!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: Andrey <andrey_ryabov@bk.ru>
Newsgroups: comp.std.c++
Subject: Re: std::pair istream >> operator
Date: Sat, 17 Nov 2007 18:30:49 CST
Organization: http://groups.google.com
Lines: 85
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <84eb137f-aa46-443e-8f6a-912487da73ad@p69g2000hsa.googlegroups.com>
References: <a7eb92bf-1ab8-438d-8bca-b6f7cfcc056c@o6g2000hsd.googlegroups.com> 
	<92a741eb-f9f2-40dc-b252-5f53a451af13@w34g2000hsg.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1195325311 13458 127.0.0.1 (17 Nov 2007 18:48:31 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 17 Nov 2007 18:48:31 +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: p69g2000hsa.googlegroups.com; posting-host=89.207.216.211; 
	posting-account=WZ-1zQoAAAAPaPX2mjMibGk6oRGuI-OS
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.1.9) 
	Gecko/20071025 Firefox/2.0.0.9,gzip(gfe),gzip(gfe)
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++:9640


> And how would you define it?  To do what?


As std::pair provided to treat two values as a single unit there can
be only one posible  implementation of  this operator described below.

std::pair class is widely used in BGL (boost/graph libray).
The question arouse due to using this library. I wanted to use an
algorithm implemented with  BGL by a friend of mine using. His library
had this operator defined, as well as my program had. That made me
think that it was quite strange that there had not beed such operator
defined in std namespace.

-------------------------------------------------------
#include <iostream>

namespace my_ns {

template <class First, class Second>
std::istream & operator >> (std::istream & in, std::pair<First,
Second> & p) {
/* debug */	std::cout<<"my_ns::operator >> ";
	return in>>p.first>>p.second;
}

}

namespace his_ns {

template <class First, class Second>
std::istream & operator >> (std::istream & in, std::pair<First,
Second> & p) {
/* debug */	std::cout<<"his_ns::operator >> ";
	return in>>p.first>>p.second;
}
}


int main() {
	using namespace std;
	pair<int, float> p;

	using namespace my_ns;

	cin>>p;

	using namespace his_ns;

	his_ns::operator >> (cin, p);

	cout<<p.first<<endl<<p.second<<endl;

	return 0;
}
-----------------------------------------------------------------


>
> > I always define it by hand.
>
> I never use std::pair to begin with, so the problem doesn't come
> up.  If I did, I would also define it by hand.  But I see no
> reason to suppose that the definition would always be the same.
>
It's worth discussing.
I was wondering how would you changed the following implementation?

template <class First, class Second>
istream & operator >> (istream & in, pair<First, Second> & p) {
	return in>>p.first>>p.second;
}

In my opinion this is the only possible implementation as it is for
operators  '<' and '=='.




---
[ 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                      ]



