220 4818 <4551abbc-43aa-4520-a91a-f8eb25a90588@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: carrierandoperator@yahoo.co.uk
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Proposal: std::sequence
Date: Mon, 3 Jun 2013 07:07:51 -0700 (PDT)
Lines: 330
Approved: news@gmane.org
Message-ID: <4551abbc-43aa-4520-a91a-f8eb25a90588@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_67_29128251.1370268471526"
X-Trace: ger.gmane.org 1370268474 4805 80.91.229.3 (3 Jun 2013 14:07:54 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 3 Jun 2013 14:07:54 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDQ2R4E5RIKBBOOGWKGQKGQESEXBCKQ@isocpp.org Mon Jun 03 16:07:54 2013
Return-path: <std-proposals+bncBDQ2R4E5RIKBBOOGWKGQKGQESEXBCKQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ye0-f197.google.com ([209.85.213.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDQ2R4E5RIKBBOOGWKGQKGQESEXBCKQ@isocpp.org>)
	id 1UjVQQ-0006Ks-GJ
	for gclcip-std-proposals@m.gmane.org; Mon, 03 Jun 2013 16:07:54 +0200
Original-Received: by mail-ye0-f197.google.com with SMTP id q4sf1088382yen.4
        for <gclcip-std-proposals@m.gmane.org>; Mon, 03 Jun 2013 07:07:53 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20120113;
        h=x-beenthere:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-google-group-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=nC4rzJRHwdl8kO0Lc6NHc6UQoemdcEbZYQ/jWJ3jj4M=;
        b=B+tXIGBAqw6y0/IHLBBgwQYxNG2kPike3myxCiqbkWy7PApfgkdPMKZAiJVui20Hbt
         bng7NFyvz9QPKayRyDYqslNajYfiE0Mz2CmyIVkdvYBQHG7lIf1D/YsYxRfxSVwtUIDN
         PIa6SuemxVOHqUm0T8FmI6rAHtvN7Ng2H4zoMU6yO9uevZVW3Tt4i7cRA3S2PIhg894k
         1fy+CozWGibeZTT1cifKLdSITWqu4EfXLNsLp0bCWF1hvp0bLvsF4G3lNG7MiGB1URXT
         97SaCfr5DudFGXkYfEjfcR8Fd0iczooN/PlCZF67F/wY5KLNH7nPTtxj0AOeppg9XVd/
         igKQ==
X-Received: by 10.236.109.227 with SMTP id s63mr12800283yhg.24.1370268473553;
        Mon, 03 Jun 2013 07:07:53 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.82.226 with SMTP id l2ls2097775qey.6.gmail; Mon, 03 Jun
 2013 07:07:52 -0700 (PDT)
X-Received: by 10.49.71.97 with SMTP id t1mr1616308qeu.0.1370268471964;
        Mon, 03 Jun 2013 07:07:51 -0700 (PDT)
X-Original-Sender: carrierandoperator@yahoo.co.uk
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?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:4818
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4818>

------=_Part_67_29128251.1370268471526
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable


I'm proposing a type I will refer to as "std::sequence" for this discussion=
..

The sequence is a primitive class I have used for years. It is a template:

EX:

 template<class T>
 class sequence {...};


It can be implemented using two member variables:
- A constant pointer to an element of the type specified by the template=20
parameter
- and a constant size_t which represents the number of elements in the arra=
y

EX:

 T* const d_element;
 const size_t d_size;


Like an array, the sequence represents a contiguous allocation of objects.=
=20
However, the sequence is not the owner of the objects. The lifetime of the=
=20
objects and the backing allocation is handled _externally_.

The member functions of the proposed class would be nearly identical to=20
std::array (sizes, element access, iterators). Additionally, std::sequence=
=20
would provide member functions which return slices of the array it=20
represents.

Containers in the standard library which hold contiguous elements could=20
also provide member functions which return a sequence.


The class is useful for combining a dynamically sized contiguous allocation=
=20
with a size parameter.

This can be useful to combine and reduce parameters:

 void foo(int* p, size_t n);
 void foo(std::sequence<int> s);


For abstraction:

 std::vector<int>& elements() {
  return this->vec;
 }


 std::sequence<int> elements() {
  return std::sequence<int>(this->vec);
 }


Unifying parameters template dependence:

From:
 void foo(vector);
 void foo(iterator);
 void foo(int*,size_t);
 template<> void foo(array) {...}


To:
 void foo(sequence);


Avoiding unnecessary promotions/temporaries:
void foo(int* p,size_t n) {
 // looks like I have to create a new vector to pass here=85
 bar(vec);
}

As well as algorithms and general conveniences.

The type requires no change to the language.

I have made the distinction between mutable and immutable sequences in my=
=20
implementation, but I assume the standard library would rather *not* make=
=20
that distinction. Mutability in this regard refers to the elements. Fixed=
=20
size and constant pointer are by design. These objects are generally very=
=20
short lived, rarely member variables, and if a sequence were created using=
=20
`new` it would probably be a programmer error.

I'd like to hear whether or not you would like to have this type in the=20
standard library and if so, how you'd change it (and why).

Thanks

--=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/?hl=3Den.



------=_Part_67_29128251.1370268471526
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<div><br></div><div>I'm proposing a type I will refer to as "std::sequence"=
 for this discussion.</div><div><br></div><div>The sequence is a primitive =
class I have used for years. It is a template:</div><div><br></div><div>EX:=
</div><div><br></div><div style=3D"background-color: rgb(250, 250, 250); bo=
rder: 1px solid rgb(187, 187, 187); word-wrap: break-word; " class=3D"prett=
yprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp;</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> sequence </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{...};</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></div></code></div><div><br><br></div><div>It can=
 be implemented using two member variables:</div><div><span class=3D"Apple-=
tab-span" style=3D"white-space:pre">	</span>- A constant pointer to an elem=
ent of the type specified by the template parameter</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">	</span>- and a constant size=
_t which represents the number of elements in the array</div><div><br></div=
><div>EX:</div><div><br></div><div style=3D"background-color: rgb(250, 250,=
 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word; " class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;T</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> d_element</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp;</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> size_t d_size</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></div></code></div><div><br><br></div><div>Like a=
n array, the sequence represents a contiguous allocation of objects. Howeve=
r, the sequence is not the owner of the objects. The lifetime of the object=
s and the backing allocation is handled _externally_.</div><div><br></div><=
div>The member functions of the proposed class would be nearly identical to=
 std::array (sizes, element access, iterators). Additionally, std::sequence=
 would provide member functions which return slices of the array it represe=
nts.</div><div><br></div><div>Containers in the standard library which hold=
 contiguous elements could also provide member functions which return a seq=
uence.</div><div><br></div><div><br></div><div>The class is useful for comb=
ining a dynamically sized contiguous allocation with a size parameter.</div=
><div><br></div><div>This can be useful to combine and reduce parameters:</=
div><div><br></div><div style=3D"background-color: rgb(250, 250, 250); bord=
er: 1px solid rgb(187, 187, 187); word-wrap: break-word; " class=3D"prettyp=
rint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> p</span><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 style=3D"color: #660;" class=3D"styled-by-prettify">);</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">sequence</span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> s</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span></div></code></div><div><br><br></div><div>For abstract=
ion:</div><div><br></div><div style=3D"background-color: rgb(250, 250, 250)=
; border: 1px solid rgb(187, 187, 187); word-wrap: break-word; " class=3D"p=
rettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">vector</span><span style=3D"col=
or: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> elements</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><font color=3D"#000000"><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">&nbsp; </span></font><span style=3D"color: #008;=
" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">this</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">-&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">vec</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp=
;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br>&nbsp;=
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">sequence</span>=
<span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> elements</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">sequence</span><span style=3D"color: #080;" class=3D"styled=
-by-prettify">&lt;int&gt;</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">this</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
-&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vec</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v><div><br><br></div><div>Unifying parameters template dependence:</div><di=
v><br></div><div>From:</div><div style=3D"background-color: rgb(250, 250, 2=
50); border: 1px solid rgb(187, 187, 187); word-wrap: break-word; " class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">vector</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>&nbsp;</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
iterator</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">*,</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">size_t</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>&nbsp;</span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">template</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;&gt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f=
oo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">array</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{...}</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span></div></code></div><div><br><br></=
div><div>To:</div><div><div style=3D"background-color: rgb(250, 250, 250); =
border: 1px solid rgb(187, 187, 187); word-wrap: break-word; " class=3D"pre=
ttyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">sequence</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);</span></div></code></div><br></div><div><br></di=
v><div>Avoiding unnecessary promotions/temporaries:</div><div style=3D"back=
ground-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); wor=
d-wrap: break-word; " class=3D"prettyprint"><code class=3D"prettyprint"><di=
v class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-=
prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> p</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">size_t n</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>&nbsp;</span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// looks like I have to create a new vector to pass here=85</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;bar</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">vec</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">}</span></div></code></div><div><br></div><div>As=
 well as algorithms and general conveniences.</div><div><br></div><div>The =
type requires no change to the language.</div><div><br></div><div>I have ma=
de the distinction between mutable and immutable sequences in my implementa=
tion, but I assume the standard library would rather *not* make that distin=
ction. Mutability in this regard refers to the elements. Fixed size and con=
stant pointer are by design. These objects are generally very short lived, =
rarely member variables, and if a sequence were created using `new` it woul=
d probably be a programmer error.</div><div><br></div><div>I'd like to hear=
 whether or not you would like to have this type in the standard library an=
d if so, how you'd change it (and why).</div><div><br></div><div>Thanks</di=
v><div><br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_67_29128251.1370268471526--

.
