r/cpp • • Sep 14 '26

operator<>: A Dream of Higher-order Metaprogramming Parity

https://www.elbeno.com/blog/?p=1871
78 Upvotes

12 comments sorted by

18

u/Top-Mycologist-5460 Sep 14 '26

Thanks, nice article. My usual workaround is using a bunch of operator()'s on the value level for that, and then decltype-and-declval-ing all the way through.

31

u/jdehesa Sep 14 '26

This is the kind of thing I guess I get why it could be useful but also might make me lose my shit if I ever saw it in an actual codebase I have to work on.

16

u/13steinj Sep 14 '26

"Why does the author sound familiar to me?"

searches name of website.

Of course, it's Ben Deane.

14

u/UnusualPace679 Sep 14 '26

I don't think many of us want to duplicate the value-world facilities in the type-world. Converting types to values and dealing with them with reflection functions is likely the future, even though this means we need to sprinkle [: :] and other tricks here and there.

3

u/GabiTheProgrammer Sep 14 '26

Very nice read.

-1

u/zerhud Sep 14 '26 edited Sep 15 '26

We can

template<typename t> struct _type_c {
t operator +() const ;
};

template<typename t> constexpr auto type_c = _type_c<t>;

template<typename t> concept is_type_c = … ;

template<template<typename…>typename t>
struct _tmpl_c{
constexpr auto operator()(is_type_c auto&&… args) {
return type_c<t<decltype(+args)…>>;
}
};

9

u/TheChief275 Sep 14 '26

if this is actually a serious comment, please indent each line of code with 4 spaces for proper formatting

4

u/zerhud Sep 14 '26

I was writing on mobile phone, it’s hard 😂😂😂

1

u/zerhud Sep 14 '26

Spaces are not working :(

1

u/TheChief275 Sep 15 '26

Works for me tho? (on mobile even)

template<typename t>
struct _type_c {
    t operator +() const;
};

template<typename t>
constexpr auto type_c = _type_c<t>;

template<typename t>
concept is_type_c = …;

template<
    template<typename…> typename t>
struct _tmpl_c {
    constexpr auto operator()(
        is_type_c auto&&…args)
    {
        return type_c<t<decltype(+args)…>>;
    }
};

1

u/zerhud Sep 15 '26

Oh, looks nice, is it just four spaces? Why my triple backticks do nothing?

6

u/Dragdu Sep 15 '26

Old reddit vs new reddit has different rules for markdown. Because of course it does.

Triple backticks should work on new reddit, but not on old reddit (which needs the 4 spaces on each line and also a newline before the codeblock).