220 13651 <8808df5e-62c4-459d-acd9-00e63adb9476@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Jeaye Wilkerson <contact@jeaye.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Generic std::size, a la std::begin
Date: Wed, 1 Oct 2014 01:00:55 -0700 (PDT)
Lines: 136
Approved: news@gmane.org
Message-ID: <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="----=_Part_1001_708181512.1412150455215"
X-Trace: ger.gmane.org 1412406696 3751 80.91.229.3 (4 Oct 2014 07:11:36 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 4 Oct 2014 07:11:36 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCT5TQUQ54HBBH53X2QQKGQE7P6EV3I@isocpp.org Sat Oct 04 09:11:30 2014
Return-path: <std-proposals+bncBCT5TQUQ54HBBH53X2QQKGQE7P6EV3I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f200.google.com ([209.85.192.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCT5TQUQ54HBBH53X2QQKGQE7P6EV3I@isocpp.org>)
	id 1XaJV4-0005G9-Bq
	for gclcip-std-proposals@m.gmane.org; Sat, 04 Oct 2014 09:11:30 +0200
Original-Received: by mail-pd0-f200.google.com with SMTP id ft15sf5123192pdb.7
        for <gclcip-std-proposals@m.gmane.org>; Sat, 04 Oct 2014 00:11:28 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=JdgDX3aWJdEi1noQ8rqMvV97X1aUZ9WyhTn6niunJuU=;
        b=iEHveYy768kiDS8QWRI9xmvT+xV0ytjbkSUcwoQ8LsShlMS09RkOVopW/a30YOBIac
         Ukftv8u97YwCN8SIkVnAB1QKA7uBGRIjv2A92ncnxgw5sn/a6IRs0owTjsv6XUd+K2b6
         6V2UdHZm5Zs2SXpQpWIe70XzZbPKY5osRE7nirP7qPUhzOvJGJMrmu2JocS91Iocc9yI
         6mGIPm9idIvylQu2H8+ua5AKC3lD6pi8EqbvUqFEDpoiya7oDsdPENW3f+T097wpPRwb
         rRpngfmNKc9XQ1l4rAm5nbsD1ewsdQnDw9gmMvBRnvqqKP1HL9BAUqb9wZ+qWMYv2fb8
         fv7A==
X-Gm-Message-State: ALoCoQnoZJ+HPYZwf+A09sBOoMQxHwtLDe3lu1PksQSSKOI7ZktRp7V+916zrxYDxc0AcA75H6mC
X-Received: by 10.66.171.231 with SMTP id ax7mr5065304pac.29.1412406688198;
        Sat, 04 Oct 2014 00:11:28 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.20.132 with SMTP id n4ls1406372ige.10.canary; Sat, 04 Oct
 2014 00:11:27 -0700 (PDT)
X-Received: by 10.50.92.104 with SMTP id cl8mr2507271igb.1.1412406687602;
        Sat, 04 Oct 2014 00:11:27 -0700 (PDT)
Original-Received: by 10.50.144.195 with SMTP id so3msigb;
        Wed, 1 Oct 2014 01:00:57 -0700 (PDT)
X-Received: by 10.50.122.2 with SMTP id lo2mr203362igb.4.1412150457084;
        Wed, 01 Oct 2014 01:00:57 -0700 (PDT)
X-Original-Sender: contact@jeaye.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:13651
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13651>

------=_Part_1001_708181512.1412150455215
Content-Type: text/plain; charset=UTF-8

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

-- 

--- 
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/.

------=_Part_1001_708181512.1412150455215
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Folks,<br><br>The stdlib could use a few new function temp=
lates 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 con=
tainers, including C-style arrays. The interface is as follows:<br><br><div=
 class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); borde=
r-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-w=
rap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span><pre><a name=3D"line-2"></a><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> size</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">T </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">c</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><a name=3D"line-3"></a><span style=3D"color: #008;" class=3D"style=
d-by-prettify">template</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">ty=
pename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><a name=
=3D"line-4"></a><span style=3D"color: #008;" class=3D"styled-by-prettify">a=
uto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> size</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">T </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">c</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><a name=3D"line-5"></a><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">template</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">size_t N</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><a name=3D"line-6=
"></a><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">size_t </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> size</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">T </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(&amp;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">arr</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">)[</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">N</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]);=
</span></pre></div></code></div><br>A working implementation and some examp=
le code is included here: <a href=3D"http://coliru.stacked-crooked.com/a/a3=
21818e19f0efae">http://coliru.stacked-crooked.com/a/a321818e19f0efae</a><br=
><br>The two main benefits of this addition are as follows:<br><ol><li>Supp=
ort 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/1=
2c71f9970e37463">http://coliru.stacked-crooked.com/a/12c71f9970e37463</a></=
p><p>Regards,<br>Jeaye<br></p></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 />

------=_Part_1001_708181512.1412150455215--

.
