Article View: comp.lang.c
Article #2146Re: Iterators over slices and views and ranges analogs in C
From: Ross Finlayson
Date: Thu, 03 Dec 2026 18:27
Date: Thu, 03 Dec 2026 18:27
144 lines
7826 bytes
7826 bytes
On 12/03/2026 10:00 AM, Ross Finlayson wrote:
> 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.
>
>
>
>
>
>
It's like when Josuttis says "... iterators are the key, glue, code
(to standard collections & containers, in C++) ...", it's like
"oh rly, Iterables and Single-Abstract-Methods the functional also
make a lot of sense in Java". ("Back to Basics: Iterators.")
Then it's clear that without templates in C that's lots of duplicated
code and explosion of the namespace, yet, with the account of,
"underloading" now involved, can also reduce less, which can result
smaller code thus for more code re-use in the code-cache.
"As this is generic code, it works for all containers,
all data structures, and all the element types, ...,
you can use it for strings, ...."
"... using the iterators as glue code, this works with
all abstractions, ..., you will not find the base class
for iterator, ..., everything that behaves like an iterator
is an iterator, ..., arrays or pointers, ...."
Here the point is that the backing of the "array" or iterator
is a bunch of slices, then to result that functions are to
result making passes over iterators, for example whether or
not an iterator has a "remove()" element, here not as
it's a view not a mutator, then about the combinatorial
explosion of types to contain that with just these "buffers"
and "names" types of fixed-length and natural alignments.
Technical Details
Message-ID:
<y92cnSmcTMcBKYz2nZ2dnZfqn_SdnZ2d@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!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com>Show 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!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 03 Dec 2026 18:27:40 +0000 Subject: Re: Iterators over slices and views and ranges analogs in C Newsgroups: comp.lang.c References: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Thu, 3 Dec 2026 10:27:24 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <y92cnSmcTMcBKYz2nZ2dnZfqn_SdnZ2d@giganews.com> Lines: 144 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-epgNnwIeUq7mPpDhs/kknSMbvpKsUozbQfMo7b4q4PQp3hgIC8RqJ2KWRsWEnlFUG5oQyqZIsMITCPs!gaj4Iehwrc5ug+UC/lJA0wNSCKO5hYwnipp3OSp68W0zKtsPJgI3oWdFtIEzdcc07SFxM0bogwMW 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