Article View: comp.lang.c
Article #2145Iterators over slices and views and ranges analogs in C
From: Ross Finlayson
Date: Thu, 03 Dec 2026 18:00
Date: Thu, 03 Dec 2026 18:00
110 lines
6206 bytes
6206 bytes
Hello, good day, been trying to figure out an account of generics in C,
that are specialized to type according to _Generic breaking out function
overloads according to type, and for example breaking out
sizes of arrays to "underloads", which uses a macro to ## concatenate
for example after # stringifying identifiers, and making the
controlling-expression of the generic then as with regards to varioously
declared pointers of the types with the sizes matching to
functions overloads/underloads with given lengths or otherwise
parameters like enums, then with __auto_type and using pointers to
fixed-size arrays so that array-decay-to-pointer preserves the type
under the point for function resolution, then about how to figure out a
way to make for generic sorts of containers, yet mostly about an adapter
to "iterator" and with regards "views/ranges", so then that usually
account of do/while and while/do and for in looping-constructs has
something to do when data is considered to be of particular types
not-necessarily contiguous their memory (storage according to C) as
contiguous and as about the notion of memory as super-scalar or
unbounded vis-a-vis the randomly accessible, secondarily.
Of course, one may suggest to simply use a higher-level language
where these sorts concepts as they are ("interfaces" usually in
sth. like Java, "concepts" for example in C++ or as for template-types,
with regards typename and the like, or templates in C++ about
specializing the generics with the combined yet distinguished
language and idiom of both C++ and Java, primarily C++ for its
derivation from C and primarily Java for its own account of innovations
later folded into C++, like for accounts of CharSequence vis-a-vis
views/ranges and the like, yet here just pointing out that C++'s
terms are C++'s and Java's are Java's and C's are C's, and other
languages like Rust or Python just stick out as making things
different to be different and not compatible like "enum" in Rust
or whatever's "Pythonic" these days, that Rust and Python are
considered second-cousins while C -> C++ -> Java is considered
more of a line. (The language not necessarily the runtime.)
/* pseudo-code: "overloading" */
f_t _Generic( controlling_expression,
t1_t: f_t1(),
t2_t: f_t2(),
default: static_assert /* omitting default is also static_assert */
)
/* pseudo-code: "underloading" */
t1_t t1;
t2_t t2;
f_t _Generic( controlling_expression ## _t,
t1_t: t(1),
t2_t: t(2)
)
So, then what's sort of being figured is about how to go from array
types, to variant, then while yet at compile-time, to dispatch over
the introduced types, to result generics and their specialization,
while resulting writing algorithms only to the "underloads", which
for example C++ just generates many, many function-bodies, the idea
being about how to generate 1 function-body "agnostic of type, yet,
specialized to type", since the types are very simple and of only
a few given types (the built-ins then tuples of fixed sizes).
Then the account of iterators basically is about begin(), end(), next(),
or for example since enumerations/vectors in Java like
for next()/hasNext(), noticeably an opposite sort of account,
then about what forever (rather, whatever) makes for being
Iterable (interface in Java, concept in C++) about iterators and
iterables, has that many, many times here have been written adapters
to accessors to result generic access then about how to make that
so for C in a nice sort of way, then also to result that a direct,
natural reading surfaces the same code in C++ and for example
idiomatically in C, C++, and Java, about the interfaces that
the C libraries can provide, where the boundaries are according to C,
since the process & thread they're according to the C runtime where
it's hosted, usual accounts of code and loading & linking and so on,
thus for the perceived requirement of iterators in C, according
to functional signatures and a simple convention of name-spacing
by function names, in C.
Anyways I'd be curious if someone would point to something for
example "oh forever since C++ was invented there was a an idiomatic
C approach to iterators then later other standard sorts collections
& containers, some national laboratory uses it for all the things
and it's the same since forever", I'd be interested in that.
Otherwise I'm looking at how to make one, figuring then
it will be stable and standard and well-defined with the guarantees
and so on, about many and various approaches basically to
un-bounded, un-structured data as text, according to bounded structures,
and iterators.
Thanks for reading, it's invited your opinion.
Technical Details
Message-ID:
<-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!local-4.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-1.nntp.ord.giganews.com!nntp.giganews.com!local-4.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 03 Dec 2026 17:59:53 +0000 Newsgroups: comp.lang.c X-Mozilla-News-Host: snews://giganews.com:443 From: Ross Finlayson <ross.a.finlayson@gmail.com> Subject: Iterators over slices and views and ranges analogs in C Date: Thu, 3 Dec 2026 10:00:10 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> Lines: 110 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-H34oFKsCV+iNtG4ArTOFnb73XxkFYwkvdJ4uUC6Pmjvl+6sB6OchsatyN0j90cCJJ2EE7FbuoYd0Dm3!NKH8yZYXtmmLZFHpXA5hK00arnaqA//CzIn6Pa8ypimoiXgvmaBa06wTIuthRBGpkTvcxxuMo86Y X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40