News for hackers. Stuff that matters.
Re:We used C++20 to eliminate a class of runtime bugs by jcelerier on Friday January 14, 2022 @03:36PM (#29940057)
I'm curious about your use case for calling the vector(size_t, value_type) constructor (vector<string> v1 { 42, "foo" }).

I'm on a codebase of a few hundred kloc and the need for a vector initialized to anything but the default value pretty much never came up. It uses boost, Qt, llvm and two dozen other libraries, yet there is a grand total of eight instantiations of that constructor in it.

When putting a breakpoint, it turns out that all the calls to it I could trigger actually just initialize with the default value statically (e.g. vector<T*> v{x, nullptr};).

Re:We used C++20 to eliminate a class of runtime bugs by rixed on Friday January 14, 2022 @05:39PM (#29941499)
Easy because since the bite I'm adding some comments after those initialisations where I really intend to call a given constructor.

Three instances I could grep immediately, all from the same file:

  std::vector<std::tuple<std::optional<qreal>, QString, QColor>>
      values(  // Not list-init
          numValues, std::make_tuple(std::nullopt, QString(), QColor()));
  (...)
  std::vector<size_t> nextTupleIdx(numValues, 0);  // Not list-init here!
  std::vector<bool> done(numValues, false);        // Not list-init here!
I do not doubt a single second that there are 36 ways to write this that are simpler, more efficient and more readable. Yet I would like to hear your suggestion.
Re:We used C++20 to eliminate a class of runtime bugs by jcelerier on Friday January 14, 2022 @07:16PM (#29942256)
All your examples can be replaced by

    std::vector<T> vec(numValues); 
as vector value-initializes.

Personally I prefer an explicit reserve or resize, but still..