220 13652 <20141004004445.GA8207@lenovo> article
Path: news.gmane.org!not-for-mail
From: Jeaye <contact@jeaye.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Generic std::size, a la std::begin
Date: Sat, 4 Oct 2014 08:44:46 +0800
Lines: 86
Approved: news@gmane.org
Message-ID: <20141004004445.GA8207@lenovo>
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: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1412408912 25498 80.91.229.3 (4 Oct 2014 07:48:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 4 Oct 2014 07:48:32 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCT5TQUQ54HBBRGMX2QQKGQEKXOMJIA@isocpp.org Sat Oct 04 09:48:26 2014
Return-path: <std-proposals+bncBCT5TQUQ54HBBRGMX2QQKGQEKXOMJIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yk0-f199.google.com ([209.85.160.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCT5TQUQ54HBBRGMX2QQKGQEKXOMJIA@isocpp.org>)
	id 1XaK4k-0000sL-Kq
	for gclcip-std-proposals@m.gmane.org; Sat, 04 Oct 2014 09:48:22 +0200
Original-Received: by mail-yk0-f199.google.com with SMTP id 131sf3314607ykp.6
        for <gclcip-std-proposals@m.gmane.org>; Sat, 04 Oct 2014 00:48:21 -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:subject:message-id:references
         :mime-version:in-reply-to:user-agent: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:content-disposition
         :content-transfer-encoding;
        bh=zHgXYc7PWgbhkqYRo/XVEWro2BkSQSLFxPD46Rl0Jw0=;
        b=AlssBU478sUmj+0jjQXOdDo32H3THyWXZlfguVIt/LXGgRLN5pW9pPX9BbPud39xPg
         orlpZ6Aixd00HA/0ssnetdMmh3SQyX3S9mnZon1JvP8TXCDp+s3DSTBrEDl2OYenMHmG
         1V0JGZ8RBzKb1fkrsJ6XCrT/u7Rd3Zuw64zgX5jgJDiukQKmb78raFYNFdmfPcQVYaxO
         MYplTr89z3motDpcl5/DbvOszXriC40+IVAjGnWO82T96oSErQpKrr5JPdtQmAeEmyxl
         D6Cabwy882VDexAja1iwLTETMCnkU3bwQnudxj4jlUMn3z3Lu0V 
X-Gm-Message-State: ALoCoQmSX5v3TIyI4JYMI0SXOl65NyvTqLWG916Znf3FfLI++l7lRl18gl9S95Z3IMyrf8SqEDo7
X-Received: by 10.52.28.234 with SMTP id e10mr8609797vdh.1.1412408901330;
        Sat, 04 Oct 2014 00:48:21 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.164.169 with SMTP id yr9ls1423609igb.11.canary; Sat, 04 Oct
 2014 00:48:20 -0700 (PDT)
X-Received: by 10.66.191.230 with SMTP id hb6mr12090058pac.72.1412408900566;
        Sat, 04 Oct 2014 00:48:20 -0700 (PDT)
Original-Received: from gproxy8-pub.mail.unifiedlayer.com (gproxy8-pub.mail.unifiedlayer.com. [67.222.33.93])
        by mx.google.com with SMTP id gy11si8950110pbd.86.2014.10.04.00.48.20
        for <std-proposals@isocpp.org>;
        Sat, 04 Oct 2014 00:48:20 -0700 (PDT)
Received-SPF: neutral (google.com: 67.222.33.93 is neither permitted nor denied by domain of contact@jeaye.com) client-ip=67.222.33.93;
Original-Received: (qmail 18898 invoked by uid 0); 4 Oct 2014 07:48:19 -0000
Original-Received: from unknown (HELO CMOut01) (10.0.90.82)
  by gproxy8.mail.unifiedlayer.com with SMTP; 4 Oct 2014 07:48:19 -0000
Original-Received: from host356.hostmonster.com ([66.147.240.156])
	by CMOut01 with 
	id yvoE1o0023P9sDu01voHL4; Sat, 04 Oct 2014 01:48:18 -0600
X-Authority-Analysis: v=2.1 cv=LbyvtFvi c=1 sm=1 tr=0
 a=FWcRu7l24H2k7lU03+oCMQ==:117 a=FWcRu7l24H2k7lU03+oCMQ==:17 a=DsvgjBjRAAAA:8
 a=f5113yIGAAAA:8 a=J0QyKEt1u0cA:10 a=EcLp88ubB2YA:10 a=IkcTkHD0fZMA:10
 a=8CndYJbwAAAA:8 a=OT0Zg4JGCOQA:10 a=QjwW5pXuTuYA:10 a=nhc-Yy2rAAAA:8
 a=1XWaLZrsAAAA:8 a=Dup7ZuK9AAAA:8 a=bz8a1_PjObXHEVq3ssAA:9 a=QEXdDO2ut3YA:10
 a=0nZfiNUXQXkA:10 a=KVQ1-MIdho4A:10 a=AxGrDXFQKmsA:10
Original-Received: from [58.182.227.13] (port=48221 helo=lenovo)
	by host356.hostmonster.com with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256)
	(Exim 4.82)
	(envelope-from <contact@jeaye.com>)
	id 1XaK4c-0002jl-Ms
	for std-proposals@isocpp.org; Sat, 04 Oct 2014 01:48:15 -0600
In-Reply-To: <8808df5e-62c4-459d-acd9-00e63adb9476@isocpp.org>
User-Agent: Mutt/1.5.23 (2014-03-12)
X-Identified-User: {2376:host356.hostmonster.com:jeayeco1:jeaye.com} {sentby:smtp auth 58.182.227.13 authed with contact+jeaye.com}
X-Original-Sender: contact@jeaye.com
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 67.222.33.93 is neither permitted nor denied by domain of
 contact@jeaye.com) smtp.mail=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>
Content-Disposition: inline
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:13652
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13652>

I should note, the current alternative is

std::distance(std::begin(arr), std::end(arr))

which is

  1. Not constexpr
  2. Terribly verbose

Regards,
Jeaye

On Wed, Oct 01, 2014 at 01:00:55AM -0700, Jeaye Wilkerson wrote:
>    Folks,
>=20
>    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 fo=
r
>    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, includin=
g
>    C-style arrays. The interface is as follows:
>=20
>    template  <typename T>
>=20
>  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]);
>=20
>    A working implementation and some example code is included here:
>    [1]http://coliru.stacked-crooked.com/a/a321818e19f0efae
>=20
>    The two main benefits of this addition are as follows:
>=20
>    =C2=A01.=C2=A0Support for C-style arrays in generic implementations; t=
his also makes
>        the std::xxx_n series more compatible with C-style arrays
>    =C2=A02.=C2=A0Allowance of user-provided fully specialized versions of=
 std::size for
>        custom types
>=20
>    An example of 2 being:
>    [2]http://coliru.stacked-crooked.com/a/12c71f9970e37463
>=20
>    Regards,
>    Jeaye
>=20
>    --
>=20
>    ---
>    You received this message because you are subscribed to a topic in the
>    Google Groups "ISO C++ Standard - Future Proposals" group.
>    To unsubscribe from this topic, visit
>    [3]https://groups.google.com/a/isocpp.org/d/topic/std-proposals/KyWbsV=
meGgY/unsubscribe.
>    To unsubscribe from this group and all its topics, send an email to
>    [4]std-proposals+unsubscribe@isocpp.org.
>    To post to this group, send email to [5]std-proposals@isocpp.org.
>    Visit this group at
>    [6]http://groups.google.com/a/isocpp.org/group/std-proposals/.
>=20
> References
>=20
>    Visible links
>    1. http://coliru.stacked-crooked.com/a/a321818e19f0efae
>    2. http://coliru.stacked-crooked.com/a/12c71f9970e37463
>    3. https://groups.google.com/a/isocpp.org/d/topic/std-proposals/KyWbsV=
meGgY/unsubscribe
>    4. mailto:std-proposals+unsubscribe@isocpp.org
>    5. mailto:std-proposals@isocpp.org
>    6. http://groups.google.com/a/isocpp.org/group/std-proposals/

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.
