r/programmingcirclejerk • • 24d ago

Note that we’re not actually going to be using C++20 coroutines. I’m just using the co_yield keyword.

https://brevzin.github.io/c++/2026/11/04/operator-for/
69 Upvotes

13 comments sorted by

35

u/al2o3cr 24d ago

Token sequences + template metaprogramming would produce the most AMAZING error messages

22

u/OorNaattaan 24d ago

I bet ^^ this is what the article means by "With Great Power Comes Great Potential For Fun"

31

u/imachug 24d ago

Posting anything related to modern C++ on this subreddit is cheating at this point

28

u/OorNaattaan 24d ago edited 24d ago

Sorry: I saw something from De Raadt posted here yesterday and thought cheating was allowed on this sub.

57

u/dingwinger1225 24d ago
template <class R, class P, int I>
struct inject_tokens_impl<std::ranges::filter_view<R, P>, I> {
    static consteval auto apply(Direction dir, info init, info body) -> void {
        inject_tokens(^^{ auto \id("__r"sv, I+1) = \id("__r"sv, I).base(); });
        inject_tokens(^^{ auto \id("__pred"sv, I+1) = \id("__r"sv, I).pred(); });
        inject_tokens_impl<R, I+1>::apply(dir,
            ^^{ auto&& \id("__elem"sv, I+1) },
            ^^{
                if (\id("__pred"sv, I+1)(\id("__elem"sv, I+1))) {
                    \tokens(init) = \id("__elem"sv, I+1);
                    \tokens(body);
                }
            }
        );
    }
};

this reminds me of when I needed to split a string in c++ once and someone posted similar syntax vomit and said it's a mark of the elegance of the STL

17

u/_Ilobilo_ 24d ago

std::views::split

28

u/Flash_Kat25 24d ago

std::shut::up

6

u/CatProgrammer 23d ago

This is just LaTeX.

28

u/dangerbird2 in open defiance of the Gopher Values 24d ago
.consteval {
    for2(
        ^^{ int& i },
        ^^{ v  | std::views::filter(is_even) | std::views::reverse },
        ^^{
            i += 1;
        });
}

show this to someone in 2005 and they'd say it's Erlang or some shit

26

u/daidoji70 24d ago

Jesus I swear c++ is a disease of the mind.  

3

u/itzjackybro 20d ago

This is literally reinventing Rust proc-macros.

2

u/Major_Barnulf LUMINARY IN COMPUTERSCIENCE 14d ago

It is $CURRENT_YEAR and c++ is still pioneering new ways to reinvent the for-loop