remix logo

Hacker Remix

C++26: more constexpr in the core language

92 points by jandeboevrie 21 hours ago | 84 comments

mcdeltat 16 hours ago

Anyone else getting concerned about the rate of development of the C++ Standard vs compiler implementation? We don't even have feature complete C++20 on the major compilers yet. C++23 is even less implemented. How will the committee handle this? Will they reduce feature additions at some point in the future?

https://en.cppreference.com/w/cpp/compiler_support

dahart 9 hours ago

FWIW, I can’t ever remember a time when the most widely used compilers in practice weren’t around 5-10 years behind changes in the standard. Part of the issue is that adoption takes time, and always will. A lot of people using C++ professionally don’t want to be on the bleeding edge of language changes. Some do, but a lot don’t, for good reasons.

When I was in college in the 90s, templates were new and had iffy support. In the 2000s, STL was still problematic. I remember the Microsoft Compiler spitting out error messages on STL types that were so long the compiler couldn’t handle the string length and truncated the error message so you couldn’t see what the problem was. In the late 00s and early 10s I worked in games, we wanted stability and for the code to be as non-tricky as possible (for example by banning use of exceptions, STL containers, and most casual heap allocation, among other things.) So we used older compilers by choice. My current job publishes an SDK and APIs that people have been using for many years, they need to be backward compatible and we can’t impose recent language features on our users because not everyone uses them, we have to stick to features that compile everywhere, so I still see lots of C++{11,14,17}.

OneDeuxTriSeiGo 13 hours ago

It is worth noting that one of the main reasons why C++ standard evolution is faster nowadays is because the "bare minimum" for consideration of acceptance in the standard is working examples on a fully functioned compiler. This tends to make it a lot easier for other compilers to implement those features as there is at minimum a working reference to compare against (vs older still unimplemented features like modules where nobody really ironed out how to properly implement them until after they were shoehorned into the standard)

pjmlp 9 hours ago

Yes, it changed my point of view that it is about time WG21 goes back to the old ways of only standardising existing practice, or at very least proposals without preview implementations shouldn't even get discussed in first place.

The problem is that with the new wind C++ got with C++11, its role in GCC and LLVM, and domains like HPC, HFT, GPGPU, WG21 got up to 300 something members, everyone wanting to leave their name on a C++ standard, many proposing features in PDF form only.

And since in ISO driven languages, what gets into a standard, does so by votes, not technical implementation merit, it is about doing a proper campaign to get the bases to vote for your feature, while being persistent enough to keep the process going. Some features have more than 20 revisions on their proposal.

einpoklum 5 hours ago

The other side of that coin is that if you required "technical implementation merit", then only people or groups who have strong experience with C++ compilers would be able to propose things.

I'm not saying that the existing situation is ideal and it's certainly not a dichotomy, but you have to consider the detriments as well as the benefits.

pjmlp 4 minutes ago

Great, languages like C++ relevance on the industry, should have a "you should be this high to play" entrance price.

Also I should add this is no different on wannabe C and C++ replacements, or most other programming languages with similar market share.

Go try to do a drive by pull request for a new language feature on those ecosystems.

Measter 3 hours ago

You could have a two-stage process. Stage 1 would be the proposal, where you have the discussion on whether the feature is desirable or not, which can then be provisionally accepted. At this point it is not in the standard.

Then you have Stage 2, which would require an actual working implementation, so it can be properly tested and such. Acceptance in Stage 2 would result in the feature being in the standard.

Pet_Ant 15 hours ago

Maybe knowing where a language is going will help them implement older features? Also, some things are technically easy once all the conceptual wrinkles are ironed out. There is no reason some of these can't be added before C++20 is 100% supported.

veilrap 18 hours ago

I always like these new comile time features getting into the C++ spec.

I'm actually looking forward to the related reflection features that I think are currently in scope for C++26. I've run into a number of places where the combination of reflection and constexpr could be really valuable... the current workarounds often involving macros, runtime tricks, or both.

steveklabnik 18 hours ago

> I'm actually looking forward to the related reflection features that I think are currently in scope for C++26.

The core of reflection should be in C++26, yes. In my understanding, there's more to do after that as well. We'll see when the final meeting is done.

Quitschquat 20 hours ago

It would be cool to have the entire language and runtime available at compile-time like in Lisp

MrRadar 18 hours ago

The D language basically does that. You can write D programs that evaluate D code at compile time to generate strings of new D code which you can then basically compile-time eval into your code as needed. Combined with the extremely powerful compile-time reflection capabilities of D it's the closest thing I've seen to Lisp metaprogramming outside of that family of languages and it's easier to read than Rust macros or C++ template metaprogramming.

TOGoS 16 hours ago

Every time I hear about D it sounds awesome. I actually used it to prototype an image collage-composing algorithm which I then rewrote in Scala[1], and the D version might have been nicer to write.

The only reason I didn't write more stuff in D was that the stack traces from my programs were pretty much useless. Maybe I was supposed to set a --better-stack-traces flag when I compiled it or something idk.

[1] One of the algorithms used by https://github.com/TOGoS/PicGrid

sfpotter 12 hours ago

D is really, really good. I hope it gets more love soon. D's focus on just getting shit done, lightning builds, QOL improvements all over the place, actually good modules, templates and metaprogramming that work, simpler more regular syntax, any memory management paradigm you want, being fully batteries included, being super easy to cross compile, being able to span all the way from Python/C# slop all the way down to tight-as-you-like C code... It's an amazing language and is getting better all the time. A real C++ successor. It has become my secret weapon! Maybe I actually don't want it to blow up soon, since it gives me a huge edge on anyone stuck with C++, which gets worse every release (how slow do builds have to get before people lose it completely?).

lenkite 11 hours ago

Last time I tried D, the standard library required garbage collection. Has that changed ? Can I plugin my custom allocators for the stdlib ?

gavinray 4 hours ago

Many of the functions in Phobos are not `@nogc` compatible, yes.

That being said, I can't think of many scenarios in which an application where user-code is all `@nogc` would be hindered by occasional GC'ed stdlib methods.

One standout example of viability is the "dplug" library for realtime audio processing plugins and the commercial AuburnSounds VST's written by the author.

neonsunset 7 hours ago

> way from Python/C# slop

That's one of the craziest things I've heard here. These two languages sit at opposite ends of abstraction.

AdieuToLogic 15 hours ago

> Combined with the extremely powerful compile-time reflection capabilities of D it's the closest thing I've seen to Lisp metaprogramming outside of that family of languages ...

Scala gets pretty close to LISP-level of metaprogramming support between its intrinsic support for macros[0] (not to be confused with the C/C++ preprocessor of the same name), the Scalameta project[1], and libraries such as Shapeless[2].

Not comparing Scala to D, just identifying a language with similar functionality.

0 - https://docs.scala-lang.org/scala3/reference/metaprogramming...

1 - https://scalameta.org/

2 - https://github.com/milessabin/shapeless

kazinator 20 hours ago

It would be cool, except for the entire language that is available at compile-time being C++, and thus entirely unsuitable for manipulating C++ programs.

gpderetta 18 hours ago

Yes. It is not like C++ compilers are written in C++.

klipt 19 hours ago

Circle C++ does that

dataflow 18 hours ago

Could you show some examples?

yuppiemephisto 17 hours ago

Maybe too far afield, but: https://leanprover-community.github.io/lean4-metaprogramming...

Gives what you wished for. It's functional, though (among other things). Unlike most lisps, (dependently) typed. But hey, available at compile-time.

112233 11 hours ago

Recent C++ changes seem like polishing your firewood before burning it. Yes, they make perfect sense, but often they are a fix to a problem that committee introduced by cutting down previous proposals (e.g. forcing lambdas to be single return statement, then relaxing it).

Half of new features feel like "how to make STL implementation less embarassing".

Meanwhile there still is no language support for e.g. debugging constexpr, or printing internal private state of objects in 3rd party code.

HelloNurse 8 hours ago

How could a debugger make sense of "internal private state of objects in 3rd party code"? Only a portion of the stack frames of linked functions (input parameters coming from known code, maybe expected return values) has a presumable type.

gpderetta 7 hours ago

> forcing lambdas to be single return statement, then relaxing it

At no point were lambdas single return statement. You might be confusing it with some other language feature. Or language.

pjmlp 9 hours ago

> printing internal private state of objects in 3rd party code

That is more a dynamic monkey patching programming language kind of thing.

greesil 11 hours ago

Compile time debugging? Is #warning not good enough?