C++26 Expansion Tricks

HeliumHydride | 24 points

I look at C++ code like this and feel like it's from a different planet. These are keywords and approaches I just never use myself. Templates ocassionally, but auto templates? std::meta? Whatever [:Member:] is? nonstatic_data_members_of? std::is_void_v? Plus the lambdas make this syntax even worse.

It feels like I'm looking at a conlang instead of C++.

Not hating the author, I'm sure they know their stuff and this is useful to someone. Just looking at this from the perspective of an ordinary C++ programmer, it looks very alien.

Night_Thastus | 25 days ago

To me, this seems like it increases cognitive load, which is the opposite of what it ought to be. At some point the abstraction is so abstract, that you have to stop and think about what the [redacted] you're actually reading, without it just making intrinsic sense.

If you want to enumerate over a bunch of items to print them out, do that. Don't wrap it up in some obscure language feature.

Stuff like this is why, of the two main "C with classes" extension languages, I prefer ObjC over C++. If I really need the speed of C++, I can just use it, but you'd better believe it'll be straightforward C++/STL. At all other times, it's easier to grok ObjC, easier to work with it, and (again) the cognitive load over and above 'C' is really minimal compared to C++.

I guess I'm just one of the old-fashioned folks who think that just because something was difficult to write, it shouldn't be difficult to read. Code clarity wins over brevity in my book any day.

spacedcowboy | 25 days ago

I'm tracking all G++ 14+ flags and warnings that reduce the likelihood of writing unsafe or incorrect C++ code. What am I missing?

    # Primary Warning Set
    -Wall -Wextra

    # Enhanced Warning Sets
    -Wpedantic -Weffc++

    # Type Safety
    -Wshadow -Wold-style-cast -Wcast-align -Wconversion -Wsign-conversion 
    -Wdouble-promotion -Wimplicit-fallthrough=5 -Wlogical-op -Wuseless-cast
    -Wlifetime -Wsuggest-final-types -Wsuggest-final-methods -Wzero-as-null-pointer-constant

    # C++ Features
    -Wcatch-value=3 -Wctad-maybe-unsupported -Wdeprecated-copy-dtor

    # Memory and Object Safety
    -Wdangling-reference -Wpessimizing-move -Wredundant-move -Wclass-conversion
    -Wuse-after-free=3 -Wmismatched-new-delete

    # Declaration Consistency
    -Wmismatched-tags -Wredundant-tags -Wredundant-decls -Wnon-template-friend
    -Wattribute-alias=2

    # Advanced Analysis
    -Wstrict-aliasing=3 -Wstrict-overflow=5 -Warray-bounds=2 -Wzero-length-bounds
    -Wnrvo -Winterference-size

    # Attribute Suggestions
    -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn 
    -Wmissing-noreturn

    # Miscellaneous
    -Warith-conversion -Wundef -faligned-new

    # Static Analysis
    -fanalyzer -Wanalyzer-too-complex
greenavocado | 25 days ago

> (fnc.template operator()<Elts>() && ...);

Better not to do this. Cast the operand to void first. Otherwise if someone overloads operator, (the wisdom of that is another matter) it will affect the behavior.

dataflow | 25 days ago

Is this a preview of things to come or just macho template programming?

It seems very esoteric, hard to understand.

Some of the examples don't even compile, but in any case, this isn't the working man's C++.

indigoabstract | 25 days ago

[dead]

curtisszmania | 25 days ago