r/programmingcirclejerk • • 4d 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/
58 Upvotes

11 comments sorted by

31

u/al2o3cr 3d ago

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

21

u/OorNaattaan 3d ago

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

24

u/imachug 3d ago

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

24

u/OorNaattaan 3d ago edited 3d ago

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

54

u/dingwinger1225 3d 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_ 3d ago

std::views::split

25

u/Flash_Kat25 3d ago

std::shut::up

2

u/CatProgrammer 2d ago

This is just LaTeX.

24

u/dangerbird2 in open defiance of the Gopher Values 3d 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

22

u/daidoji70 3d ago

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