220 8368 <14C8EC03-2834-45DA-B6D1-64178D13A88F@gmail.com> article
Path: news.gmane.org!not-for-mail
From: Howard Hinnant <howard.hinnant@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Obtaining a non-const iterators from a
 const_iterator and a non-const reference to the container
Date: Thu, 2 Jan 2014 10:51:11 -0500
Lines: 37
Approved: news@gmane.org
Message-ID: <14C8EC03-2834-45DA-B6D1-64178D13A88F@gmail.com>
References: <68deff4f-5f1d-440e-b6cd-1e5077a3ff96@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\))
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1388677880 26829 80.91.229.3 (2 Jan 2014 15:51:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 2 Jan 2014 15:51:20 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCK2HM4L6YERB44VS2LAKGQEYUJ3IYQ@isocpp.org Thu Jan 02 16:51:23 2014
Return-path: <std-proposals+bncBCK2HM4L6YERB44VS2LAKGQEYUJ3IYQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yh0-f69.google.com ([209.85.213.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCK2HM4L6YERB44VS2LAKGQEYUJ3IYQ@isocpp.org>)
	id 1VykYG-0005fF-Ps
	for gclcip-std-proposals@m.gmane.org; Thu, 02 Jan 2014 16:51:17 +0100
Original-Received: by mail-yh0-f69.google.com with SMTP id a41sf17983799yho.4
        for <gclcip-std-proposals@m.gmane.org>; Thu, 02 Jan 2014 07:51:15 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:subject:from:in-reply-to:date
         :message-id:references:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type:content-transfer-encoding;
        bh=PvKzBNCjuEAquwZp+P6ISGqEnRawgIiShiEHGSETBK4=;
        b=lwFrGx/U0NHsAWOMdu/6banFlCZpVPOA72qbQarpmB417DQDi0wen1hT7guYrLDkl5
         qQGYoECU+AIsGxxCS10p2bWwBxYM9dlyNXCcRvmMp0AIVdnr7tMClBfJEptYeBugsKfd
         SVVsAZP/XfOGGndcQy2frH3G5bb6PNLSZQ+N97wBdZfbGPcZQc2JiWawM+VJEjh0f/1F
         QfPcInURDrc22fQGu8EWPizNH0V4TfUuIeY4ls98FAkG5ZUM2rM8Upm2YpZLTWRwhN+O
         TXElltvqWdl+hKAzWmbHya920rUo7+riAmF2UHJsiRuRRtPZSJbAwg4Ubck6omEDJOd9
         O9JQ==
X-Gm-Message-State: ALoCoQmdQ1eZrgHgHQxFxMxbSxw2hLUhlmILurlh/wgnbR+8g5Ar2U3iOaVsNyxhTc2YrFeyX6mQ
X-Received: by 10.58.54.97 with SMTP id i1mr1494976vep.40.1388677875730;
        Thu, 02 Jan 2014 07:51:15 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.60.37 with SMTP id e5ls4527743qer.84.gmail; Thu, 02 Jan
 2014 07:51:15 -0800 (PST)
X-Received: by 10.49.116.78 with SMTP id ju14mr141548107qeb.57.1388677875176;
        Thu, 02 Jan 2014 07:51:15 -0800 (PST)
Original-Received: from mail-ig0-x232.google.com (mail-ig0-x232.google.com [2607:f8b0:4001:c05::232])
        by mx.google.com with ESMTPS id hi9si24130108qcb.73.2014.01.02.07.51.15
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 02 Jan 2014 07:51:15 -0800 (PST)
Received-SPF: pass (google.com: domain of howard.hinnant@gmail.com designates 2607:f8b0:4001:c05::232 as permitted sender) client-ip=2607:f8b0:4001:c05::232;
Original-Received: by mail-ig0-f178.google.com with SMTP id ut6so33912178igb.5
        for <std-proposals@isocpp.org>; Thu, 02 Jan 2014 07:51:14 -0800 (PST)
X-Received: by 10.42.227.195 with SMTP id jb3mr59633804icb.27.1388677874641;
        Thu, 02 Jan 2014 07:51:14 -0800 (PST)
Original-Received: from [10.0.1.4] (cpe-24-59-186-27.twcny.res.rr.com. [24.59.186.27])
        by mx.google.com with ESMTPSA id f5sm72203307igc.4.2014.01.02.07.51.13
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 02 Jan 2014 07:51:13 -0800 (PST)
In-Reply-To: <68deff4f-5f1d-440e-b6cd-1e5077a3ff96@isocpp.org>
X-Mailer: Apple Mail (2.1510)
X-Original-Sender: howard.hinnant@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of howard.hinnant@gmail.com designates 2607:f8b0:4001:c05::232 as
 permitted sender) smtp.mail=howard.hinnant@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8368
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8368>

On Jan 1, 2014, at 11:19 PM, Xavi Gratal <gratal@gmail.com> wrote:

> Given a const_iterator ci to an element of a container c, it is already p=
ossible to obtain a non-const iterator with:
>=20
> auto i=3Dstd::advance(c.begin(),std::distance(c.cbegin(),ci);
>=20
> However, this is extremely inefficient for non-random-access containers. =
I would like to add some mechanism to the standard containers so that given=
 a non-const reference to the container and a const_iterator, it is possibl=
e to obtain a non-const iterator in constant time.
> This would be useful in a scenario where an algorithm takes a const refer=
ence to a container and finds some interesting element inside, returning a =
const_iterator to it. Then, as long as you have a non-const reference to th=
e container, you should be able to modify the element you found. It is alre=
ady possible to erase it using a const_iterator.
>=20
> Is there any reason why such a facility doesn't exist for the standard co=
ntainers?

It does exist, and it is efficient:

   auto i =3D c.erase(ci, ci);

Howard

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.
