Article View: comp.lang.c
Article #2254Re: Iterators over slices and views and ranges analogs in C
From: Janis Papanagnou
Date: Sat, 05 Dec 2026 17:09
Date: Sat, 05 Dec 2026 17:09
117 lines
6302 bytes
6302 bytes
On 2026-12-05 16:43, David Brown wrote:
> On 05/12/2026 15:36, Janis Papanagnou wrote:
>> On 2026-12-04 15:38, David Brown wrote:
>>> On 04/12/2026 14:58, Janis Papanagnou wrote:
>>>>
>>>> Grafting features to a language that wasn't designed to support
>>>> those regularly often lead to clumsy, ugly, inconsistent designs.
>>>> So while it's not surprising, but it also won't change what "C"
>>>> actually is (and what's discussed here, the C-language).
>>>
>>> I don't think _Generics are clumsy, ugly or inconsistent - they are
>>> actually quite clear and simple. But they do get bulky if you want
>>> to support more than one parameter.
Well, if it's considered (for any underlying thought) good to use
macros with C-generics then I think something got wrong. - Anyway,
that was just my first association when I saw it used, and I'm
also repelled when I see the necessity of lexical "specialities"
like the underscore-uppercase (which I just dislike; an indication
of a "grafted feature"). - Don't bother explaining the reasoning,
I know it; and it doesn't make things better. - But as it's only
a personal dislike of details in the "C" language it's anyway not
worth a dispute.
>>
>> That's fair. I actually was referring to things like the example
>> above (using it with macros!), and statements that I found that
>> C-generics - to "make most sense" - would be used with macros.
>> (Myself, I cannot judge.)
>>
>
> _Generics are very often wrapped in macros. And certainly long macros
> have the inconvenience of needing line continuation characters when
> split into multiple lines. But that's an inconvenience of macros in
> general, rather than a _Generic thing.
Yes, sure. But see above.
> [...]
>>> I think RTTI is perhaps more important if you have complicated
>>> exceptions in code - exception types can be passing through your
>>> handlers that don't really know much about the types being thrown.
>>
>> (I don't see how that would be imposed by the use of exceptions.)
>
> I did not say (or mean to imply) that the use of RTTI is /imposed/ or
> required for exceptions.
Of course. I read it as that RTTI obtains [perhaps] more importance
in that general complex exception scenario. My point was that I don't
see how RTTI would support exceptions.
To get back to your original text (quoted above). It's not untypical
that hierarchies of exception handlers know only a specific subset of
information. You're using also hierarchies of exceptions and can take
advantage of polymorphism here. RTTI is completely unnecessary, IMO,
also in "complicated exceptions".
> You can certainly use one without the other.
For sure.
> But I believe that one use of RTTI is in more advanced exception
> handling. (Imagine a function that catches any exception passing
> through, logs some information about it, then re-throws it.)
And I still don't see where RTTI would be useful in that scenario.
(What you describe actually is the standard use of C++-exceptions.)
>
>>
>>>
>>> Once I am able to make use of C++26 and reflection in my code, I can
>>> definitely see use-cases for it. At the very least, my debug printfs
>>> will have nicer output for enumeration types :-)
>>
>> Yes, that's true; to spare you writing a bit own code to write in
>> this case.
>>
>
> Yes. It also helps keep things consistent. Making inconsistencies as
> close to impossible as practical is more important than reducing the
> code written.
>
> A particularly likely use-case would be for "count the enumerators"
> situations. Often you have :
>
> enum States {
> state_initialising,
> state_idle,
> state_starting,
> state_running,
> state_stopping,
>
> no_of_states
> }
>
> or perhaps
>
> constexpr auto last_state = state_stopping;
>
> There are a few ways to write your count of enumerators, and lots of
> enumeration uses where such a count can be useful. Each method has its
> disadvantages, such as needing manual update when the enumeration is
> changed, or introducing "fake" values (like "no_of_states" above) that
> don't really belong in the enumeration and mess with useful compiler
> warnings like "-Wswitch". With C++26 reflection, it will be easy to
> have things like :
>
> constexpr auto no_of_states = count_enum(^^States);
Well, I have no issues with end-of-taglist values like "no_of_states".
A useful thing that I accept (and often use) as typical C-idiom.
Janis
Technical Details
Message-ID:
<11f1ggn$2dad1$2@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> <11esd12$mfam$1@raubtier-asyl.eternal-september.org> <11et39b$rj55$1@news.xmission.com> <11ett3b$1a41p$1@dont-email.me> <11euadh$1gp4t$1@dont-email.me> <11euckd$1ht9i$1@raubtier-asyl.eternal-september.org> <11eugtg$erg$4@dont-email.me> <11euj8b$1lhf1$1@dont-email.me> <11f17h5$2dad1$1@dont-email.me> <11f1beh$2vtg1$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com> Newsgroups: comp.lang.c Subject: Re: Iterators over slices and views and ranges analogs in C Date: Sat, 5 Dec 2026 18:09:43 +0100 Organization: A noiseless patient Spider Lines: 117 Message-ID: <11f1ggn$2dad1$2@dont-email.me> References: <-kGdnSzB4bWEM4z2nZ2dnZfqn_WdnZ2d@giganews.com> <11esd12$mfam$1@raubtier-asyl.eternal-september.org> <11et39b$rj55$1@news.xmission.com> <11ett3b$1a41p$1@dont-email.me> <11euadh$1gp4t$1@dont-email.me> <11euckd$1ht9i$1@raubtier-asyl.eternal-september.org> <11eugtg$erg$4@dont-email.me> <11euj8b$1lhf1$1@dont-email.me> <11f17h5$2dad1$1@dont-email.me> <11f1beh$2vtg1$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 05 Dec 2026 17:09:44 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2533793"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19J2HiXNbDUBdYPiYkjxYV1"; posting-host="89c37fd5d8f581f1579ba8626b33c1d2" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:LqI4WoXyoLWRCqTZIpvWuil6JzU= sha256:3xHIZrYHxa8PFHvzAgsK3eBPVlfIhnBYcdyUHa50quY= sha1:qmcIHsCK5CjmLNviArH+zFlqaSA= sha256:gfJtx/SWI//mIxhmmVrPNjRpwAz0EuLBfEaryJGaqEo= In-Reply-To: <11f1beh$2vtg1$1@dont-email.me> Content-Language: en-US