220 33181 <55df161b-f0c5-4d81-ad1d-882425e7bf8a@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Alexander Zaitsev <zamazan4ik@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: [idea for proposal] Adding std::shift to <algorithm>
Date: Wed, 12 Jul 2017 04:18:02 -0700 (PDT)
Lines: 180
Approved: news@gmane.org
Message-ID: <55df161b-f0c5-4d81-ad1d-882425e7bf8a@isocpp.org>
References: <bd1a5d3b-ccc1-44ab-91cc-a4d7195c9dc3@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_7946_1506611560.1499858282949"
X-Trace: blaine.gmane.org 1499858290 24794 195.159.176.226 (12 Jul 2017 11:18:10 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 12 Jul 2017 11:18:10 +0000 (UTC)
Cc: dan@soundradix.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDGLZGV44EEBB24KTDFQKGQERUMJYCQ@isocpp.org Wed Jul 12 13:18:04 2017
Return-path: <std-proposals+bncBDGLZGV44EEBB24KTDFQKGQERUMJYCQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f197.google.com ([209.85.161.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDGLZGV44EEBB24KTDFQKGQERUMJYCQ@isocpp.org>)
	id 1dVFeZ-0005qJ-Qv
	for gclcip-std-proposals@m.gmane.org; Wed, 12 Jul 2017 13:17:59 +0200
Original-Received: by mail-yw0-f197.google.com with SMTP id b82sf15422146ywc.11
        for <gclcip-std-proposals@m.gmane.org>; Wed, 12 Jul 2017 04:18:05 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=b3rztP0INML4Ex2LE9vGUgXV4zSsjEKmOMpzEddBPuU=;
        b=FTXRdLS6RvyRZU2kZFdqwi2z+ppri5TV6Q671r0zA8ZJTWJcS+L4eWQuiE2PCXyyMq
         pgd1L6kTZn8BvhTUStpVjDhcvZdriXaUskjdvyOkN4c419Ilr9KLvroOIQ/RzPlFGanN
         cocibDoginS/xsUOPbJQErw/4zRPOEr8AnKO25ImHxO8Ml83S7KWpny6CbvsGDokt1F+
         jQj3j4zKOLAPm/bzoXkyZSf7ZFRmKENEl82hFoSl1vSeBGrXvzMdQErJ2Kt+Er8COsO5
         hDXQLuaod+7mVKQkTwd/uMkY307uFS7Ch0V1QPiMmg+7+JkQnPZvhlHc3hU5gf8D+V/b
         jwzw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=b3rztP0INML4Ex2LE9vGUgXV4zSsjEKmOMpzEddBPuU=;
        b=ES8cw1pOLjFEWYvOdOomaSpKi4izGz6rG2VpiJXAiVk24NCpLKK+LkfdkDmdx27l3h
         2dRAEHi5EE/qbRFOhTU/3w0CEf/UwHyHZ3LMAOy2RNg98AbWb91s5tLFJHZgYTzR9otf
         e6V5I6xT+aHhr6LP/81VjSZN/UmxXUj53IguoGahJPhjEf+93MGLZ2KhJAO/BdUvwgIp
         jtMM36yXWw+eo8w9EN7pXV1JoSVAXcLwr4BFylRuxhE0OT6KAVy1x9YTGflDalb3KmA2
         ckctk9erOb74YfJuxrk8ENHj7NrH1K+IjPbJaxkhp8ECSCySR05LxWFbsSTzqdIpCBS8
         YcKw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=b3rztP0INML4Ex2LE9vGUgXV4zSsjEKmOMpzEddBPuU=;
        b=VEgChzT4LX/H8HiqeX1+UyeQY5Cdn+TTU7WPDMXoI8i47Z6WhT9nyf40D2ASpOd8g0
         JnSzBSGCdDmLG9b/bW+8qIySEMSYw8iJ2iMe3z5CbBUw6IpYVINji0bU7R3e4HmeXIDG
         LYrhdVBFfoIDLj1o0N8i3YP8F6Tcv4MOYBnvQml5wNptmFCr0kzAcuCAlnxHQ9+t7ZWQ
         utYPkKvStqQTD+Znk8ULSnl1pLFEALFTwQQL1FRktmA+1n2LKp76vX+z6Z4KwCrHdA4H
         fPa7V4FCOFqADqMMQjyV8OCuN4ppfds6yaiKefHCe17rWbdwcF7sMy24opqL9BXO4yhO
         pDNQ==
X-Gm-Message-State: AIVw113bS1ManQaPHtQRr0Ntpv6zs7Hwt1raukY2Q1PVNCZbpPMLD3TP
	JMsv4fegXRi7Qp7f
X-Received: by 10.129.160.141 with SMTP id x135mr2879931ywg.131.1499858284914;
        Wed, 12 Jul 2017 04:18:04 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.98.3 with SMTP id d3ls1262169itc.15.gmail; Wed, 12 Jul 2017
 04:18:03 -0700 (PDT)
X-Received: by 10.36.104.200 with SMTP id v191mr317768itb.2.1499858283396;
        Wed, 12 Jul 2017 04:18:03 -0700 (PDT)
In-Reply-To: <bd1a5d3b-ccc1-44ab-91cc-a4d7195c9dc3@isocpp.org>
X-Original-Sender: zamazan4ik@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:33181
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33181>

------=_Part_7946_1506611560.1499858282949
Content-Type: multipart/alternative; 
	boundary="----=_Part_7947_606884531.1499858282949"

------=_Part_7947_606884531.1499858282949
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello.

Really nice idea! But i have some suggestions:
* shift should return iterator (or two)
* it should be constexpr

Also i suggest you create PR to Boost.Algorithm (or we can work together -=
=20
i will help you as mush as possible). And after including into=20
Bost.Algorithm we can write proposal to C++ Standard.

=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 12 =D0=B8=D1=8E=D0=BB=D1=8F 2017 =D0=B3., 1=
2:53:19 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=
=D0=BB=D1=8C d...@soundradix.com=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> Hi,
>
> Would anyone be interested in adding std::shift to <algorithm>?=20
>
> It would be similar to both:
> - std::rotate, but without moving the head elements back to the tail. Thi=
s=20
> would allow a more efficient implementation and clearer semantics in case=
=20
> rotation is not needed as well as correctness in case rotation is undesir=
ed.
> - <algorithm>'s std::move/std::move_backward (depending on the shift=20
> direction).
>
> std::shift should probably accommodate both left and right shifts by one=
=20
> of:
> - giving it either begin() and end(), or rbegin() and rend(), similar to=
=20
> how std::rotate works for both left and right rotations. The advantage is=
=20
> compactness of the implementation.
> - allowing the shift count parameter to be either positive or negative.=
=20
> The advantage is compactness, though it might not be clear which directio=
n=20
> is which - to be consistent with rotate, positive integers should shift t=
o=20
> the left.
> - having std::shift_right and std::shift_left functions. The advantage is=
=20
> clarity when calling the methods, although the same argument could be mad=
e=20
> for having separate std::rotate_left and std::rotate_right instead of=20
> std::rotate, which we don't have.
>
> Here's a sample implementation of a shift to the right direction:
>
> template<class BidirIt>=20
> void shift_right(BidirIt first, BidirIt last, unsigned int n =3D 1)=20
> {=20
>     std::move_backward(first, last - n, last);=20
> }
>
> This demonstrates that while std::shift is implementable with=20
> std::move/std::move_backward,
> 1) It isn't immediately clear from the code (at least to my eyes) that=20
> this is a shift right, unless you are intimately familiar with=20
> std::move_backward.
> 2) Different calls, either to std::move or to std::move_backward, are=20
> required, depending on the shift direction.
>
> So, implementing std::shift would allow writing more readable code.
>
> Thanks,
> Dan
>

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/55df161b-f0c5-4d81-ad1d-882425e7bf8a%40isocpp.or=
g.

------=_Part_7947_606884531.1499858282949
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello.<div><br></div><div>Really nice idea! But i have som=
e suggestions:</div><div>* shift should return iterator (or two)</div><div>=
* it should be constexpr</div><div><br></div><div>Also i suggest you create=
 PR to Boost.Algorithm (or we can work together - i will help you as mush a=
s possible). And after including into Bost.Algorithm we can write proposal =
to C++ Standard.<br><br>=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 12 =D0=B8=D1=8E=D0=
=BB=D1=8F 2017 =D0=B3., 12:53:19 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C d...@soundradix.com =D0=BD=D0=B0=D0=BF=
=D0=B8=D1=81=D0=B0=D0=BB:<blockquote class=3D"gmail_quote" style=3D"margin:=
 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
dir=3D"ltr">Hi,<div><br></div><div>Would anyone be interested in adding std=
::shift to &lt;algorithm&gt;?=C2=A0</div><div><br></div><div>It would be si=
milar to both:</div><div>- std::rotate, but without moving the head element=
s back to the tail. This would allow a more efficient implementation and cl=
earer semantics in case rotation is not needed as well as correctness in ca=
se rotation is undesired.</div><div>- &lt;algorithm&gt;&#39;s std::move/std=
::move_backward (depending on the shift direction).</div><div><br></div><di=
v>std::shift should probably accommodate both left and right shifts by one =
of:</div><div>- giving it either begin() and end(), or rbegin() and rend(),=
 similar to how std::rotate works for both left and right rotations. The ad=
vantage is compactness of the implementation.</div><div>- allowing the shif=
t count parameter to be either positive or negative. The advantage is compa=
ctness, though it might not be clear which direction is which - to be consi=
stent with rotate, positive integers should shift to the left.<br></div><di=
v><div>- having std::shift_right and std::shift_left functions. The advanta=
ge is clarity when calling the methods, although the same argument could be=
 made for having separate std::rotate_left and std::rotate_right instead of=
 std::rotate, which we don&#39;t have.</div></div><div><br></div><div>Here&=
#39;s a sample implementation of a shift to the right direction:</div><br><=
div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187=
,187);word-wrap:break-word"><code><div><span style=3D"color:#008">template<=
/span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">clas=
s</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Bidir=
It</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> =
<br></span><span style=3D"color:#008">void</span><span style=3D"color:#000"=
> shift_right</span><span style=3D"color:#660">(</span><span style=3D"color=
:#606">BidirIt</span><span style=3D"color:#000"> first</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">BidirIt</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#008">last</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">unsigned</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">int</span><span style=3D"color:=
#000"> n </span><span style=3D"color:#660">=3D</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660">=
)</span><span style=3D"color:#000"> <br></span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> <br>=C2=A0 =C2=A0 std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">move_backward</span><sp=
an style=3D"color:#660">(</span><span style=3D"color:#000">first</span><spa=
n style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#008">last</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">-</span><span style=3D"color:#000"> n</span><span style=3D"=
color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">last</span><span style=3D"color:#660">);</span><span style=3D"color:=
#000"> <br></span><span style=3D"color:#660">}</span><span style=3D"color:#=
000"><br></span></div></code></div><div><br></div><div>This demonstrates th=
at while std::shift is implementable with std::move/std::move_backward,</di=
v><div>1) It isn&#39;t immediately clear from the code (at least to my eyes=
) that this is a shift right, unless you are intimately familiar with std::=
move_backward.</div><div>2) Different calls, either to std::move or to std:=
:move_backward, are required, depending on the shift direction.</div><div><=
br></div><div>So, implementing std::shift would allow writing more readable=
 code.</div><div><br></div><div>Thanks,</div><div>Dan</div></div></blockquo=
te></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/55df161b-f0c5-4d81-ad1d-882425e7bf8a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/55df161b-f0c5-4d81-ad1d-882425e7bf8a=
%40isocpp.org</a>.<br />

------=_Part_7947_606884531.1499858282949--

------=_Part_7946_1506611560.1499858282949--

.
