220 15807 <1499974.zpI02sfgj3@basis> article
Path: news.gmane.org!not-for-mail
From: Taahir Ahmed <ahmed.taahir@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Output-Restricted Variants in the <algorithm> Header
Date: Fri, 23 Jan 2015 21:59:28 -0600
Lines: 116
Approved: news@gmane.org
Message-ID: <1499974.zpI02sfgj3@basis>
References: <5cfa43db-742d-4eec-9dfc-02e30d12728f@isocpp.org> <D416C630-83F3-4D22-95CD-907A37BF85BF@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/signed; boundary="nextPart5671826.A4aCVNUkvb"; micalg="pgp-sha1"; protocol="application/pgp-signature"
X-Trace: ger.gmane.org 1422071981 22987 80.91.229.3 (24 Jan 2015 03:59:41 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 24 Jan 2015 03:59:41 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCS23TW57YDBBK5RRSTAKGQE2DCN6JY@isocpp.org Sat Jan 24 04:59:41 2015
Return-path: <std-proposals+bncBCS23TW57YDBBK5RRSTAKGQE2DCN6JY@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+bncBCS23TW57YDBBK5RRSTAKGQE2DCN6JY@isocpp.org>)
	id 1YErsr-0000Xi-39
	for gclcip-std-proposals@m.gmane.org; Sat, 24 Jan 2015 04:59:41 +0100
Original-Received: by mail-qc0-f199.google.com with SMTP id r5sf3557952qcx.2
        for <gclcip-std-proposals@m.gmane.org>; Fri, 23 Jan 2015 19:59:40 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:reply-to:subject:date:message-id
         :user-agent:in-reply-to:references:mime-version:content-type
         :x-original-sender:x-original-authentication-results:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=CyIHK2eYUz7ZFIa90ips7kVPFLWDM9xJ6xLVio1Tv3s=;
        b=U/gdemz0Ahy3GT47ZAO53LUiy405Lb54iW3fuNtqslMdfRJEHcXkE6AvHiG8Gd24zW
         dF2boVggZNQdVgf/yK41uLMZGgc6KSDHUGOlRSGz/RqEob00X3Hi3u3YmDFDk+Zmz4vo
         /I/rwg4xCmKmCERNR6uVCBzqXPCZv2CRqmVAq7Wx0JchG5eK/hUdm4YD/aA9ENxdPj1w
         GkrqKd/YhE54IL3r58d1f297IZennrvru2D8dFyBbu+lD5f6MD8ydQOTBnJZbftO06hd
         QQZVY2hj+No49XGutDs3xODmwJFiB+UmrIIJqjlevZsplr7Cvw//Brp5JOAUTDF0B4A9
         /ECA==
X-Gm-Message-State: ALoCoQnANpdvzC79+fvSNzASq46/344KBuxHAqDu1OxNM8VGflV3THvSH8an0/DXdR8mqxBvgSSw
X-Received: by 10.236.42.168 with SMTP id j28mr8228996yhb.26.1422071980126;
        Fri, 23 Jan 2015 19:59:40 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.213.103 with SMTP id nr7ls573842obc.40.gmail; Fri, 23 Jan
 2015 19:59:39 -0800 (PST)
X-Received: by 10.60.129.168 with SMTP id nx8mr6424718oeb.82.1422071979222;
        Fri, 23 Jan 2015 19:59:39 -0800 (PST)
Original-Received: from mail-ob0-x236.google.com (mail-ob0-x236.google.com. [2607:f8b0:4003:c01::236])
        by mx.google.com with ESMTPS id o184si1770926oif.15.2015.01.23.19.59.39
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 23 Jan 2015 19:59:39 -0800 (PST)
Received-SPF: pass (google.com: domain of ahmed.taahir@gmail.com designates 2607:f8b0:4003:c01::236 as permitted sender) client-ip=2607:f8b0:4003:c01::236;
Original-Received: by mail-ob0-f182.google.com with SMTP id gq1so780283obb.13
        for <std-proposals@isocpp.org>; Fri, 23 Jan 2015 19:59:38 -0800 (PST)
X-Received: by 10.202.91.137 with SMTP id p131mr6340778oib.3.1422071978635;
        Fri, 23 Jan 2015 19:59:38 -0800 (PST)
Original-Received: from basis.localnet (r74-192-230-149.lfkncmta01.lfkntx.tl.dh.suddenlink.net. [74.192.230.149])
        by mx.google.com with ESMTPSA id a91sm1590781oic.18.2015.01.23.19.59.38
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 23 Jan 2015 19:59:38 -0800 (PST)
User-Agent: KMail/4.14.3 (Linux/3.16.5-gentoo; KDE/4.14.3; x86_64; ; )
In-Reply-To: <D416C630-83F3-4D22-95CD-907A37BF85BF@gmail.com>
X-Original-Sender: ahmed.taahir@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of ahmed.taahir@gmail.com designates 2607:f8b0:4003:c01::236 as
 permitted sender) smtp.mail=ahmed.taahir@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: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:15807
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/15807>

--nextPart5671826.A4aCVNUkvb
Content-Type: text/plain; charset=UTF-8

> ... why not define an output-restricted iterator category ...?

For three main reasons:

  1) It does not fit with current practice.

     Everywhere else in the STL, wherever a range is called for, it is
     represented in half-open form using a source iterator and limit
     iterator.

     In addition, partial_sort_copy is already output-restricted, and is
     implemented in this way.

  2) It does not fit with future practice.

     Explicit specification of the output range as a half-open range
     pair means that the algorithm can be used as the "4-legged" form
     mentioned in n4128 Section (the ranges proposal), Section 3.3.8
     [1].

     Thus, there would be a straightforward interoperation with ranges,
     when they are introduced.

  3) It seems Byzantine.

     To force iterators to do a range's job requires that the iterator
     be stateful, and seems to be a lot of effort to avoid defining some
     small functions.

     Many of the functions I propose will be nearly textually identical
     to their non-restricted counterparts.  For example, take
     restricted_copy and copy.  They can share a common implementation:

     ----%<-------------------------------------------------------------

     template<class ItA, class ItD>
     std::tuple<ItA, ItD> copy_base(
         ItA a_src, ItA a_lim,
         ItD d_src, ItD d_lim,
         bool restrict_output
     )
     {
         while(a_src != a_lim && (!restrict_output || (d_src != d_lim)))
         {
             *d_src = *a_src;
             ++d_src;
             ++a_src;
         }

         return make_tuple(a_src, d_src);
     }
     
     template<class ItA, class ItD>
     std::tuple<ItA, ItD> restricted_copy(
         ItA a_src, ItA a_lim,
         ItD d_src, ItD d_lim
     )
     {
         auto lims = copy_base(a_src, a_lim, d_src, d_lim, true);
         return std::get<1>(lims);
     }

     template<class ItA, class ItD>
     ItD copy(
         ItA a_src, ItA a_lim,
         ItD d_src
     )
     {
         // Here, the fourth argument to copy_base could be anything.
         auto lims = copy_base(a_src, a_lim, d_src, d_src, false);
         return std::get<0>(lims);
     }

     ----%<-------------------------------------------------------------

     Implemented like this, there isn't any repeated code, AND all the
     dirty tricks currently used by implementations of std::copy
     (std::memmove for appropriate iterator and data types) can placed
     into copy_base.


Taahir

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4128.html#additional-overloads-of-the-algorithms

-- 

--- 
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/.

--nextPart5671826.A4aCVNUkvb
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.
Content-Transfer-Encoding: 7Bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAABAgAGBQJUwxipAAoJEP0dGB2mOaLG7loH/06VdeMn3O3A9nSEpsqricMf
EsA9N/FbcYbdYPhTrePGQ87Zo4YmYh+SzxQC8XOVaT2lAyJvQLWXuo94j4JNWmQn
kXYVDzrY3XsZ7fLFVtjX9QwC/ek3PM4cQkraKFP7ak+U/arA+Q85uSHGkbh/DKoK
ymtXmUabr+GMjwjZAmw2Rx+P02slR5bIcrg+5hILOobx7J89ejY/oEz+GARXGHTk
MJTPoLyjAdzVixZCP0ZTP5qXwIB/GhsBXXcI0c264QW0jL8ss/scgS781g+ZF9kc
z6vMPvMwsWreCrIvZ2myJUZg0BRKdmJhh3NeRfePosWj3rPvHIfzTiZMqx3OxDU=
=2+2C
-----END PGP SIGNATURE-----

--nextPart5671826.A4aCVNUkvb--


.
