Daily bit(e) of C++

Share this post

Daily bit(e) of C++ | Conditional explicit

simontoth.substack.com

Daily bit(e) of C++ | Conditional explicit

Daily bit(e) of C++ #258, C++20 conditional explicit specifier.

Šimon Tóth
Sep 16, 2023
2
Share this post

Daily bit(e) of C++ | Conditional explicit

simontoth.substack.com
Share

Since C++20, the explicit specifier can be conditional. This allows for generic code that permits implicit conversions in safe cases.

In this example, the wrapper for integral types permits implicit conversion only when the destination type can represent the full range of the source type.

Click to open in Compiler Explorer.

Leave a comment

Thanks for reading Daily bit(e) of C++! Subscribe for free to receive new posts and support my work.

2
Share this post

Daily bit(e) of C++ | Conditional explicit

simontoth.substack.com
Share
Comments
Top
New
Community

No posts

Ready for more?

© 2023 Šimon Tóth
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing