@robertfrysch7985

The `value()` method of the optional does not lead to undefined behavior, it will throw an exception if the optional is empty.

@robertfrysch7985

You don't need to spell the empty angle brackets of the plus operation, simply `std::plus{}` is fine.

@TsvetanDimitrov1976

The good news is that all the compilers were able to do the computation at compile time. The bad news is that unless I change the vector to a constexpr array, the result couldn't be used as a non-type template argument(not that we really need another way to do metaprogramming), and that std::print doesn't seem to be as optimized as I though it to be.

@embeddor3023

rare MSVC win

@testtest-qm7cj

Clang-tidy's bugprone checker warns "Folding type 'double' into type 'int' might result in loss of precision [bugprone-fold-init-type]."

@nicholaskomsa1777

auto floatSum = std::reduce( floats.begin(), floats.end(), double(0.0) ); the sum type is a templated parameter, sir!

@jeremywmurphy

Yeah, the initial value to std::accumulate is a bit of a gotcha as we all know, but the problem is using a generic algorithm in a non-generic way. That is, iterating over `data` but throwing a literal in as the initial value.
The initial value's type is up to the user, because as I think I said to you in your training some weeks ago, the user might want to use a BigNumber class, or start with a double to sum over floats. Whatever. If you just want the same type as `data` then you should not be using a literal, you should use decltype(data)::value_type{X}, where X is the identity element for the binary operation. Unfortunately, the STL does not (yet) have the utilities to determine X from the operation (AFAIK).

@RicardoCapurro

Hi, good article as usual, but I am surprised the way you are using named arguments to functions on C++, since AFAIK C++ do not support that feature yet.

I am talking about code at 1:07 on video, example""

STATIC_CHACK(evaluate_to<IntType>(input: "(- 2 2)" == 0);

and so on ...

Can you explain that?

Thanks in advance

@NiiColaOfficial

Will it actually parallelize it in any case?

@NotherPleb

Having left and right variants of fold feels so dumb, where's the generic "reverse"

@anon_y_mousse

I actually was expecting 21 because you didn't specify a type and as a predominately C developer when you don't specify a type and you use an integer looking value, it's an int. Although, it would be nice if the compiler at least said something about the automatic conversion from float to int when taking elements from the vector. It is funny though, how slowly but surely the C++ standard committee is absorbing all of Boost. I'm not sure whether I should lament the duplication of effort or the fact that programmers are so shit these days that they don't learn third party libraries and ignore everything that's not in the standard.

@nicholaskomsa1777

auto meanDiffSq = std::reduce(in.begin(), in.end(), 0.0f,
		[&](auto sum, auto x) {
			auto diff = x - mean;
			return sum + diff * diff;
		}) / in.size();

@somerandompersonintheinternet

If you are just doing a sum, fold_left_first with std::plus feels a bit "too smart" when you are reading it. As in, in the std::accumulate version, it is easy to know what the programmer's intent was. In the fold version, you have to stop and think about it.

@botsjeh

fold_right_LAST