Article View: comp.lang.c
Article #2148Re: Iterators over slices and views and ranges analogs in C
From: Ross Finlayson
Date: Thu, 03 Dec 2026 19:01
Date: Thu, 03 Dec 2026 19:01
228 lines
9817 bytes
9817 bytes
On 12/03/2026 10:27 AM, Ross Finlayson wrote:
> 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.
>
>
>
>
Sort of an, "iterview", ....
viter: view-iter
witer: write-iter (item-wise, ...)
diter: dest-iter (vector-wise, ...)
Maybe just "viter" and "witer",
lining up with "const t* const" and "t* const",
that those are "viter<t>" and "witer<t>".
Then for something like
viter -> view-iter
witer -> write-iter
xiter -> transform, product?
yiter -> output?
ziter -> vector destination?
Then of course an iterator is just some state and some function
pointers to usually make operator-overloaders what looks like
while ( *p < len_p && *q < len_q) {
*q++ = *p++;
}
typedef void (*incr_fn)() iter_incr_fn_t;
typedef void (*accr_fn)(size_t stride) iter_accr_fn_t;
typedef p(*p_fn)(viter_p_t* v) p_fn_t;
typedef struct {
void* p;
size_t size_p;
size_t len_p;
size_t off_p;
iter_incr_fn_t iter_incr_fn;
iter_accr_fn_t iter_accr_fn;
p_fn_t get_fn;
} viter_p_t;
typedef void (*fn_p)(witer_p_t* v) fn_p_t;
typedef struct {
void* p;
size_t size_p;
size_t len_p;
size_t off_p;
iter_incr_fn_t iter_incr_fn;
iter_accr_fn_t iter_accr_fn;
p_fn_t get_fn;
fn_p_t set_fn;
} witer_p_t;
So, then "viter" and "witer" are working terms, then that
for the account of vectorization that a "tuple-iterator"
is suggested, a "titer",
titer: tuple-iterator
uiter: no, ..., perhaps a sort of tuple-interator "unsigned-iterator"
Here the idea that tuples are of types yet unsigned's are of bits,
then that in the vectorization account also, some vector operations
work just fine on the vector-wide-scalar-word as bits, vis-a-vis,
packed types as tuples of a type with regular stride, hmm...
Hmm...
Technical Details
Message-ID:
<VEadnd4VkZjpIYz2nZ2dnZfqnPednZ2d@giganews.com>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-4.nntp.ord.giganews.com!nntp.giganews.com!local-1.nntp.ord.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mailReferences:
<-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> <y92cnSmcTMcBKYz2nZ2dnZfqn_SdnZ2d@giganews.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!border-4.nntp.ord.giganews.com!nntp.giganews.com!local-1.nntp.ord.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 03 Dec 2026 19:01:08 +0000 Subject: Re: Iterators over slices and views and ranges analogs in C Newsgroups: comp.lang.c References: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> <y92cnSmcTMcBKYz2nZ2dnZfqn_SdnZ2d@giganews.com> From: Ross Finlayson <ross.a.finlayson@gmail.com> Date: Thu, 3 Dec 2026 11:01:11 -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: <y92cnSmcTMcBKYz2nZ2dnZfqn_SdnZ2d@giganews.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <VEadnd4VkZjpIYz2nZ2dnZfqnPednZ2d@giganews.com> Lines: 228 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-fgW5KeZ4hQW/Y9rHlP0K5wopdQFDpYhfrRerNxyjgb2O+GlVLaMcNpm1Yka8X/vK5ygXWkJWONCnbfB!LwhAkOQjrQX4ddPqfg0ak37xsH3rbSc6JPJ6F2fmF/D9i9kSNUNYIjcsmNFuhsOiRlKwVeQd4pqM 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