3 ms·
Since C++20, you can write `explicit(false)` to indicate that a single argument constructor is intentionally implicit. Similarly, the language adds the [[fallt
by scatters 5y ago
Since C++20, you can write `explicit(false)` to indicate that a single argument constructor is intentionally implicit.
Similarly, the language adds the [[fallthrough]] statement attribute to indicate intentional fallthrough between switch case labels.
As languages improve, we should need disable comments less and less.
- quietbritishjim 5y agoWhile explicit(false) does seem like a good way to indicate that, it seems like it's just a happy accident that it exists. The intended purpose of explicit(xyz) is that xyz is a compile-time constant that depends on the template parameters of the current (template) class. A literal true or false isn't needed by the language (just include explicit or don't), but the language would be more complex if they were disallowed so it's easier to allow them. So in general, improvements to languages don't necessarily remove the need for comments over time. (On the other hand, more radical improvements might remove needs for warning comments by removing the original problem. In this case, in a language where constructors were explicit by default and you had to opt in to implicit, you wouldn't need the warning to exist in the first place.)
- bluGill 5y ago> In this case, in a language where constructors were explicit by default and you had to opt in to implicit, you wouldn't need the warning to exist in the first place A warning that authors of new languages should account for. However most of us have millions of lines of working code, and experience in our current language. As such changing to your new better language isn't trivial. That is before we get into how old languages have had a lot of effort into tools and optimizations that new ones don't have [yet?] thus making the old one better in some potentially important dimensions.