220 13702 <CAOHCbiuKV=1kQD6Mgs9j_tC7TnkgzE=z4tohAud-yWnk41HctQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Tony V E <tvaneerd@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Generic std::size, a la std::begin
Date: Mon, 6 Oct 2014 10:40:27 -0400
Lines: 176
Approved: news@gmane.org
Message-ID: <CAOHCbiuKV=1kQD6Mgs9j_tC7TnkgzE=z4tohAud-yWnk41HctQ@mail.gmail.com>
References: <8808df5e-62c4-459d-acd9-00e63adb9476@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c372da504caf0504c2108d
X-Trace: ger.gmane.org 1412606439 25709 80.91.229.3 (6 Oct 2014 14:40:39 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 6 Oct 2014 14:40:39 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCUZ5QWKNQINZU6KUECRUBGI6NI7I@isocpp.org Mon Oct 06 16:40:34 2014
Return-path: <std-proposals+bncBCUZ5QWKNQINZU6KUECRUBGI6NI7I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ee0-f72.google.com ([74.125.83.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCUZ5QWKNQINZU6KUECRUBGI6NI7I@isocpp.org>)
	id 1Xb9Sg-0005aI-1C
	for gclcip-std-proposals@m.gmane.org; Mon, 06 Oct 2014 16:40:30 +0200
Original-Received: by mail-ee0-f72.google.com with SMTP id e51sf2969109eek.7
        for <gclcip-std-proposals@m.gmane.org>; Mon, 06 Oct 2014 07:40:29 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from: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=xSpzOLNGhn2sRfNgjiC/upkOUFRAOJuTABbdMPfF/KA=;
        b=jWvmhfUUq43zt8Ey3TLMiVJfcPfVf+Frcl1iRg5uPfQoSuCcvuukrv4Kam/Yo5fs2p
         RNncclHD5i+LqwrQEpDt8mEAllSS1EqzqOyoXKzhLiLOK2sl1dSqAbmMbQbZEnL5ofZo
         +vQ/P8hnoEXSctEIf5F2kYRyaelU3GLv3jIZyb3cxNBmrU9NIDHicLvWt7VBBGhT4L0D
         DQs1+GoLqBfe6BuDiUZQ0gCF12GyHlk+Beof+OGsXDiBff9QtpGQ/DSdMuCrPIPPhYSF
         bIRGw9VjUs+2tREQvoz4Q3DvpoTXU65q2Cm0n23189PK4XNHr3Nv7z034tkLpufANG9A
         iFnA==
X-Gm-Message-State: ALoCoQlS3cF0MSTYypL4N+3n/x1OPdzMcBnuYYpqmbrmPwDot9lThstujD9+SJo2HFMJ2cmdFvkI
X-Received: by 10.180.106.197 with SMTP id gw5mr2592651wib.1.1412606429672;
        Mon, 06 Oct 2014 07:40:29 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.23.227 with SMTP id p3ls602805laf.39.gmail; Mon, 06 Oct
 2014 07:40:28 -0700 (PDT)
X-Received: by 10.112.126.194 with SMTP id na2mr24087828lbb.70.1412606428136;
        Mon, 06 Oct 2014 07:40:28 -0700 (PDT)
Original-Received: from mail-la0-x234.google.com (mail-la0-x234.google.com [2a00:1450:4010:c03::234])
        by mx.google.com with ESMTPS id b2si24367668lah.6.2014.10.06.07.40.28
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 06 Oct 2014 07:40:28 -0700 (PDT)
Received-SPF: pass (google.com: domain of tvaneerd@gmail.com designates 2a00:1450:4010:c03::234 as permitted sender) client-ip=2a00:1450:4010:c03::234;
Original-Received: by mail-la0-f52.google.com with SMTP id hz20so4452922lab.39
        for <std-proposals@isocpp.org>; Mon, 06 Oct 2014 07:40:27 -0700 (PDT)
X-Received: by 10.112.201.72 with SMTP id jy8mr24510826lbc.78.1412606427416;
 Mon, 06 Oct 2014 07:40:27 -0700 (PDT)
Original-Received: by 10.112.75.199 with HTTP; Mon, 6 Oct 2014 07:40:27 -0700 (PDT)
In-Reply-To: <8808df5e-62c4-459d-acd9-00e63adb9476@isocpp.org>
X-Original-Sender: tvaneerd@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of tvaneerd@gmail.com designates 2a00:1450:4010:c03::234 as permitted
 sender) smtp.mail=tvaneerd@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:13702
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13702>

--001a11c372da504caf0504c2108d
Content-Type: text/plain; charset=UTF-8

On Wed, Oct 1, 2014 at 4:00 AM, Jeaye Wilkerson <contact@jeaye.com> wrote:

> Folks,
>
> The stdlib could use a few new function templates to aid in creating
> generic interfaces. With C++11, we were given std::begin to account for the
> fact that C-style arrays are valid containers. I propose we add a very
> similar set of functions of accessing the size of containers, including
> C-style arrays. The interface is as follows:
>
> template <typename T>
>
> auto size(T &c);
> template <typename T>
> auto size(T const &c);
> template <typename T, std::size_t N>
> std::size_t constexpr size(T (&arr)[N]);
>
>
> A working implementation and some example code is included here:
> http://coliru.stacked-crooked.com/a/a321818e19f0efae
>
> The two main benefits of this addition are as follows:
>
>    1. Support for C-style arrays in generic implementations; this also
>    makes the std::xxx_n series more compatible with C-style arrays
>    2. Allowance of user-provided fully specialized versions of std::size
>    for custom types
>
> An example of 2 being:
> http://coliru.stacked-crooked.com/a/12c71f9970e37463
>
> Regards,
> Jeaye
>
> --
>
>
>

I would like something like this, and have written it myself a number of
times.  It would be nice to have a consistent name for it.

One concern I have, however, is how we do library extension points, in
general.  ie it is hard to call swap(x,y) correctly:

{
   using std::swap;
   swap(x, y);
}

Will users need to do the same for std::size?

In general, I'd prefer the customization/extension point be separate from
the caller's API.  ie customize std_size(), but call std::size().

To me (at least) this is similar to Herb's "Non-Virtual Interface" idiom (
http://www.gotw.ca/publications/mill18.htm).  IN this case, there is no
virtual functions, but the separation of caller-interface vs
customizer-interface is the same.

Tony

-- 

--- 
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/.

--001a11c372da504caf0504c2108d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Wed, Oct 1, 2014 at 4:00 AM, Jeaye Wilkerson <span dir=3D"ltr">&lt;<=
a href=3D"mailto:contact@jeaye.com" target=3D"_blank">contact@jeaye.com</a>=
&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px=
 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><di=
v dir=3D"ltr">Folks,<br><br>The stdlib could use a few new function templat=
es to aid in creating generic interfaces. With C++11, we were given std::be=
gin to account for the fact that C-style arrays are valid containers. I pro=
pose we add a very similar set of functions of accessing the size of contai=
ners, including C-style arrays. The interface is as follows:<br><br><div st=
yle=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);bord=
er-style:solid;border-width:1px;word-wrap:break-word"><code><div><span styl=
e=3D"color:rgb(0,0,136)">template</span><span style=3D"color:rgb(0,0,0)"> <=
/span><span style=3D"color:rgb(102,102,0)">&lt;</span><span style=3D"color:=
rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> T</span><spa=
n style=3D"color:rgb(102,102,0)">&gt;</span><span style=3D"color:rgb(0,0,0)=
"><br></span><pre><a name=3D"148d9ffbb904d893_line-2"></a><span style=3D"co=
lor:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> size</span><=
span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)=
">T </span><span style=3D"color:rgb(102,102,0)">&amp;</span><span style=3D"=
color:rgb(0,0,0)">c</span><span style=3D"color:rgb(102,102,0)">);</span><sp=
an style=3D"color:rgb(0,0,0)"><br></span><a name=3D"148d9ffbb904d893_line-3=
"></a><span style=3D"color:rgb(0,0,136)">template</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">&lt;</span><span=
 style=3D"color:rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0=
)"> T</span><span style=3D"color:rgb(102,102,0)">&gt;</span><span style=3D"=
color:rgb(0,0,0)"><br></span><a name=3D"148d9ffbb904d893_line-4"></a><span =
style=3D"color:rgb(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> s=
ize</span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color=
:rgb(0,0,0)">T </span><span style=3D"color:rgb(0,0,136)">const</span><span =
style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">&am=
p;</span><span style=3D"color:rgb(0,0,0)">c</span><span style=3D"color:rgb(=
102,102,0)">);</span><span style=3D"color:rgb(0,0,0)"><br></span><a name=3D=
"148d9ffbb904d893_line-5"></a><span style=3D"color:rgb(0,0,136)">template</=
span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,=
102,0)">&lt;</span><span style=3D"color:rgb(0,0,136)">typename</span><span =
style=3D"color:rgb(0,0,0)"> T</span><span style=3D"color:rgb(102,102,0)">,<=
/span><span style=3D"color:rgb(0,0,0)"> std</span><span style=3D"color:rgb(=
102,102,0)">::</span><span style=3D"color:rgb(0,0,0)">size_t N</span><span =
style=3D"color:rgb(102,102,0)">&gt;</span><span style=3D"color:rgb(0,0,0)">=
<br></span><a name=3D"148d9ffbb904d893_line-6"></a><span style=3D"color:rgb=
(0,0,0)">std</span><span style=3D"color:rgb(102,102,0)">::</span><span styl=
e=3D"color:rgb(0,0,0)">size_t </span><span style=3D"color:rgb(0,0,136)">con=
stexpr</span><span style=3D"color:rgb(0,0,0)"> size</span><span style=3D"co=
lor:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">T </span><span=
 style=3D"color:rgb(102,102,0)">(&amp;</span><span style=3D"color:rgb(0,0,0=
)">arr</span><span style=3D"color:rgb(102,102,0)">)[</span><span style=3D"c=
olor:rgb(0,0,0)">N</span><span style=3D"color:rgb(102,102,0)">]);</span></p=
re></div></code></div><br>A working implementation and some example code is=
 included here: <a href=3D"http://coliru.stacked-crooked.com/a/a321818e19f0=
efae" target=3D"_blank">http://coliru.stacked-crooked.com/a/a321818e19f0efa=
e</a><br><br>The two main benefits of this addition are as follows:<br><ol>=
<li>Support for C-style arrays in generic implementations; this also makes =
the std::xxx_n series more compatible with C-style arrays</li><li>Allowance=
 of user-provided fully specialized versions of std::size for custom types<=
/li></ol><p>An example of 2 being: <a href=3D"http://coliru.stacked-crooked=
..com/a/12c71f9970e37463" target=3D"_blank">http://coliru.stacked-crooked.co=
m/a/12c71f9970e37463</a></p><p>Regards,<br>Jeaye<span class=3D""><font colo=
r=3D"#888888"><br></font></span></p></div><span class=3D""><font color=3D"#=
888888">

<p></p>

-- <br>
<br><br></font></span></blockquote><div><br><br></div><div>I would like som=
ething like this, and have written it myself a number of times.=C2=A0 It wo=
uld be nice to have a consistent name for it.<br><br></div><div>One concern=
 I have, however, is how we do library extension points, in general.=C2=A0 =
ie it is hard to call swap(x,y) correctly:<br><br>{<br></div><div>=C2=A0=C2=
=A0 using std::swap;<br></div><div>=C2=A0=C2=A0 swap(x, y);<br>}<br><br></d=
iv><div>Will users need to do the same for std::size?<br><br></div><div>In =
general, I&#39;d prefer the customization/extension point be separate from =
the caller&#39;s API.=C2=A0 ie customize std_size(), but call std::size().<=
br><br></div><div>To me (at least) this is similar to Herb&#39;s &quot;Non-=
Virtual Interface&quot; idiom (<a href=3D"http://www.gotw.ca/publications/m=
ill18.htm">http://www.gotw.ca/publications/mill18.htm</a>).=C2=A0 IN this c=
ase, there is no virtual functions, but the separation of caller-interface =
vs customizer-interface is the same.<br><br></div><div>Tony<br><br></div></=
div><br></div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c372da504caf0504c2108d--

.
