Get the latest tech news

How the STL Uses Explicit


One of the papers on the docket for this week’s WG21 meeting in St Louis is P3116 “Policy for explicit” (Zach Laine, 2024). The idea of “policy,” in this context, is that LEWG wants to have something like a “style guide” for proposal-authors. If a proposal comes in with noexcept in the wrong places, or explicit, or [[nodiscard]], we want to be able to quickly tell the author how it ought to be, without a lot of the same discussion happening on every paper. Like a house style guide in newspaper-editing: if our newspaper uses the Oxford comma, and you bring in an article without it, then we can just point to the style guide, make the fix, and move on [see?], without a lot of repeated discussion of the pros and cons of the comma except insofar as you can argue that it belongs in this particular article for a really good reason.

If a proposal comes in with noexcept in the wrong places, or explicit, or[[nodiscard]], we want to be able to quickly tell the author how it ought to be, without a lot of the same discussion happening on every paper. Even when not strictly required by this rule, it can be beneficial to split a constructor into multiple overloads; for example, in order to mark a zero-argument signature noexcept, or to avoid unnecessary default-construction of temporaries. An example of deliberate non-deviation is explicit string(const StringViewLike&), where the user might be surprised if an implicit conversion from string_view allocated memory.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of STL Uses Explicit

STL Uses Explicit