220 5858 <BC0A23AE-9034-4930-BC8B-C1E6D2394CBB@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: Remove vector<bool>?
Date: Mon, 26 Aug 2013 20:56:45 -0400
Lines: 45
Approved: news@gmane.org
Message-ID: <BC0A23AE-9034-4930-BC8B-C1E6D2394CBB@gmail.com>
References: <CAGsORuDQdeWAO5yjA6=h0hW9Y0Sj4F1gcHB61udw5JFmtx+g4Q@mail.gmail.com> <b06daeb3-a585-4c55-aebf-cae643146838@isocpp.org> <CAGg_6+O_d85CBjT+cTV6vQqepUTXVvUMV_QUioS6ELpQCav6GQ@mail.gmail.com> <521B07D2.8070000@beamways.com> <7d0bc129-f8aa-4803-bbd9-bd5ca504d728@isocpp.org> <CAGsORuB8omCBfjco6i_zENDn23tx-5wg1jeHuhsGsiVMbGk+Ww@mail.gmail.com> <77e0868c-6aed-4578-acc7-7cf1227465f6@isocpp.org> <CAGsORuAAZChA8cyx4JTTqRmMNSGQXZyGdzrm9P0WVRMZSSg6Qw@mail.gmail.com> <4E5B6BD9-363D-4B42-ACA3-029301F3F54E@gmail.com> <CA+cyFgvGeOJQSfXAQg3z2TKXvFY-OYvhp6_EGMx_mxoskys7LQ@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\))
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: ger.gmane.org 1377565007 16908 80.91.229.3 (27 Aug 2013 00:56:47 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 27 Aug 2013 00:56:47 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCK2HM4L6YERBTXS56IAKGQEAI4IJ4I@isocpp.org Tue Aug 27 02:56:48 2013
Return-path: <std-proposals+bncBCK2HM4L6YERBTXS56IAKGQEAI4IJ4I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f199.google.com ([209.85.216.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCK2HM4L6YERBTXS56IAKGQEAI4IJ4I@isocpp.org>)
	id 1VE7aR-0001WL-6r
	for gclcip-std-proposals@m.gmane.org; Tue, 27 Aug 2013 02:56:47 +0200
Original-Received: by mail-qc0-f199.google.com with SMTP id n7sf4593533qcx.6
        for <gclcip-std-proposals@m.gmane.org>; Mon, 26 Aug 2013 17:56:46 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=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;
        bh=n/sb6j93wTMqYBZIe3bp9llo3zhWVEYYJWLwQ9dqfDs=;
        b=t9jCR7/2vjnCcws0fhs9NmDO36R9gFCEp4J1yBRSqiwcBR2UAk4MSjarQPiVmbqOOA
         A4KnpyIzWrf1mujo5RWVdQ8YrVWNkTWX3F46i0Av7gUpHLI7EPeH30877kywXG2wjMbc
         7ZODY1KU0O3uQYuxOIOUw5JTN+noAbETC+1fLcxV8c8smVZTQZcglBVF/A6e+agr0tff
         OjX/yXHwWRNQiJVQTrHu5BcIw9hAEzGzQyGrQEIh3aZrNs1GAM6rgyuwJSm1enFB9ayj
         93XI9MkTb4lmftsJanZqv+FJtreD/Y7iBLQ9TdInN/zK+9lbqcDI/tJbVliAPRIa/Boo
         Re+w==
X-Received: by 10.236.124.33 with SMTP id w21mr6487435yhh.15.1377565006359;
        Mon, 26 Aug 2013 17:56:46 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.42.39 with SMTP id k7ls2697385qel.52.gmail; Mon, 26 Aug
 2013 17:56:46 -0700 (PDT)
X-Received: by 10.224.37.133 with SMTP id x5mr3937669qad.40.1377565005982;
        Mon, 26 Aug 2013 17:56:45 -0700 (PDT)
Original-Received: from mail-qa0-x22a.google.com (mail-qa0-x22a.google.com [2607:f8b0:400d:c00::22a])
        by mx.google.com with ESMTPS id f10si7060750qai.16.1969.12.31.16.00.00
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 26 Aug 2013 17:56:45 -0700 (PDT)
Received-SPF: pass (google.com: domain of howard.hinnant@gmail.com designates 2607:f8b0:400d:c00::22a as permitted sender) client-ip=2607:f8b0:400d:c00::22a;
Original-Received: by mail-qa0-f42.google.com with SMTP id bn16so731385qab.1
        for <std-proposals@isocpp.org>; Mon, 26 Aug 2013 17:56:45 -0700 (PDT)
X-Received: by 10.224.36.200 with SMTP id u8mr19799544qad.64.1377565005892;
        Mon, 26 Aug 2013 17:56:45 -0700 (PDT)
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 m5sm25923577qaa.13.1969.12.31.16.00.00
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 26 Aug 2013 17:56:44 -0700 (PDT)
In-Reply-To: <CA+cyFgvGeOJQSfXAQg3z2TKXvFY-OYvhp6_EGMx_mxoskys7LQ@mail.gmail.com>
X-Mailer: Apple Mail (2.1508)
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:400d:c00::22a as
 permitted sender) smtp.mail=howard.hinnant@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) d=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:5858
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5858>

On Aug 26, 2013, at 8:16 PM, Geoffrey Romer <gromer@google.com> wrote:

> One problem this solves is that code like this is guaranteed to work:
> 
> template <typename iter_t>
> value_type& GetValue(iter_t iter) {
>   return *iter;
> }

Oops, I just realized this code is pretty dangerous even neglecting proxy iterators:

There's no enforced connection between iter_t and value_type.  So what happens when value_type is const int and:

double d;
double* dp = &d;
const int& cr = GetValue(dp);

You've got a dangling reference.  And I didn't even have to use proxies to crash this one.  To make this safer one could (use auto, or):

template <typename iter_t>
typename std::iterator_traits<iter_t>::value_type&
GetValue(iter_t iter)
{
   return *iter;
}

But by the time you've gone this far...

template <typename iter_t>
typename std::iterator_traits<iter_t>::reference
GetValue(iter_t iter)
{
   return *iter;
}

Howard

-- 

--- 
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 email 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-proposals/.

.
