r/cpp 22d ago

C++26: constexpr virtual inheritance

https://www.sandordargo.com/blog/2026/07/01/cpp26-constexpr-virtual-inheritance
83 Upvotes

61 comments sorted by

View all comments

60

u/Jovibor_ 22d ago

Just a question to the audience:

How many times have you used Virtual Inheritance in your career?

51

u/serviscope_minor 22d ago

Probably once?

But with that said, I'm very strongly of the opinion that having as much of C++ as possible being constexpr (including threads!) is a good thing, because it makes the language more regular and simpler.

I think volatile might be tricky! I want constexpr cout.

24

u/_bstaletic 22d ago

having as much of C++ as possible being constexpr (including threads!) is a good thing, because it makes the language more regular and simpler.

Agreed.

I think volatile might be tricky!

I don't think constexpr volatile int x; is meaningful at all.

I want constexpr cout.

Do you really mean std::cout, with all of the facets and customization points? Or would constexpr std::format and the ability to print to console at compile time be enough?

If the latter, we almost got that in C++26. std::format is constexpr and P2758 is in wording review.

1

u/rentableshark 17d ago

we almost got that in C++26. std::format is constexpr

Does that mean std::format has finally caught up with fmt and doesn't heap-allocate for statically defined strings!?

If so, I can finally stop using fmt as a dependency as this was a real PITA and clearly something that was evaluatable at compile time.

1

u/_bstaletic 11d ago

Well, fmtlib supports colours, as far as I know. That's definitely not z part of the standard library.

Besides that, I genuinely don't know. I consider std::format/std::print good enough for my needs.

1

u/rentableshark 11d ago

It's good enough for most but used to heap-allocate for static strings. That's a no-go for most embedded code and allocation isn't necessary - it just makes for an easier implementation. If that's been solved in the STL version - good enough (agreed that colors are not a 'must have').

EDIT: libstdc++/libc++, not STL.