June 26th, 2024

How the STL Uses Explicit

The WG21 meeting in St. Louis discusses a paper on using the `explicit` keyword in C++ proposals to establish a style guide for consistency. Guidelines differ between industry and Standard Library practices.

Read original articleLink Icon
How the STL Uses Explicit

The discussion at the WG21 meeting in St. Louis includes a paper on the policy for using the `explicit` keyword in C++ proposals. The aim is to establish a style guide for proposal authors to ensure consistency and avoid repeated discussions on the same topics. While the author suggests that all constructors should be explicit by default in industry code, exceptions exist in the 40-year-old Standard Library, like the non-explicit iterator-pair constructor of `std::vector`. The guidelines for the Standard Library differ from industry practices and focus on types aiming to enter the library. Specific rules are outlined for operator conversions, constructors based on arity, and deviations permitted with justifications. The document emphasizes the importance of maintaining consistency in C++ to prevent potential compiler errors. The guidelines are subject to updates, with future revisions expected to be adopted by the committee for standardization.

Related

My experience crafting an interpreter with Rust (2021)

My experience crafting an interpreter with Rust (2021)

Manuel Cerón details creating an interpreter with Rust, transitioning from Clojure. Leveraging Rust's safety features, he faced challenges with closures and classes, optimizing code for performance while balancing safety.

Own Constant Folder in C/C++

Own Constant Folder in C/C++

Neil Henning discusses precision issues in clang when using the sqrtps intrinsic with -ffast-math, suggesting inline assembly for instruction selection. He introduces a workaround using __builtin_constant_p for constant folding optimization, enhancing code efficiency.

Interface Upgrades in Go (2014)

Interface Upgrades in Go (2014)

The article delves into Go's interface upgrades, showcasing their role in encapsulation and decoupling. It emphasizes optimizing performance through wider interface casting, with examples from io and net/http libraries. It warns about complexities and advises cautious usage.

Tracing garbage collection for arenas

Tracing garbage collection for arenas

Tracing garbage collection in systems programming languages like C++, Rust, and Ada is compared to reference counting. A simplified tracing garbage collection approach inspired by Mark-and-Sweep is proposed for languages like Zig or Odin.

How GCC and Clang handle statically known undefined behaviour

How GCC and Clang handle statically known undefined behaviour

Discussion on compilers handling statically known undefined behavior (UB) in C code reveals insights into optimizations. Compilers like gcc and clang optimize based on undefined language semantics, potentially crashing programs or ignoring problematic code. UB avoidance is crucial for program predictability and security. Compilers differ in handling UB, with gcc and clang showing variations in crash behavior and warnings. LLVM's 'poison' values allow optimizations despite UB, reflecting diverse compiler approaches. Compiler responses to UB are subjective, influenced by developers and user requirements.

Link Icon 4 comments
By @metadat - 4 months
How can the C++ statement below even compile? Since "1" and "2" are strings (not even chars).

  std::vector<int> v = {"1", "2"} // UB
Rather than undefined behavior I'd expect a type violation error. But my C++ has gotten a bit rusty.
By @jimbob45 - 4 months
Was there ever a reason given as to why “explicit” was chosen over a hypothetical “implicit”?