Remix.run Logo
codedokode 14 days ago

By the way I looked through the code, and had to read about metaprogramming in C++. I wonder why is it so complicated? For example, why constraints like std::is_integral are represented by structs. Doesn't make much sense to me. A function wouldn't be better here?

mandarax8 14 days ago | parent | next [-]

Because the only way to do metaprogramming in C++ is via the type system. Thismakes it so you need to implement 'functions' as types.

nly 13 days ago | parent | next [-]

While this is true, you can do so much these days with functions with 'auto' return types (function templates), constexpr functions/lambdas and "if constexpr"

jstimpfle 14 days ago | parent | prev [-]

What does that mean, and is it even true, given template value parameters or constexpr for example?

fc417fc802 13 days ago | parent [-]

Sure, auto constexpr stuff can express some things. Not most things though, at least in my experience. Perhaps a skill issue on my part. Or things might have changed again. I'm "still" using C++20 after all.

> What does that mean

Have you ever noticed that the (compile time) "rules" for interacting with templated functions are somewhat different from those of non-templated functions? I don't know if "functions as types" is entirely fair but there is definitely some weirdness.

etyp 14 days ago | parent | prev [-]

Practically, it's all through this `type_traits` header that (often) end up in unreadable messes. It's all possible because of the catchy acronym SFINAE. It doesn't make much sense to me either, so I avoid it :)

https://en.cppreference.com/w/cpp/language/sfinae

Wumpnot 14 days ago | parent [-]

You don't really need to use sfinae anymore, concepts are cleaner and easier to follow, also this library appears to use concepts