mp11 icon indicating copy to clipboard operation
mp11 copied to clipboard

:new: Add `mp_quote_expr` to quote with lambda expressions

Open kris-jusiak opened this issue 4 years ago • 9 comments

Problem:

  • There is no easy way to quote metafunction directly with lambda expressions.

Solution:

  • Add mp_quote_expr.

Note:

  • mp_quote_expr requires C++20.

kris-jusiak avatar Jun 12 '21 18:06 kris-jusiak

@pdimov would you be able to take a look, please?

kris-jusiak avatar Jun 16 '21 16:06 kris-jusiak

Do you have an example of actual use? The example you're adding to the docs doesn't quite do what it says in the description; it replaces all types not having value with void, instead of finding those that have value.

You need to check feature macros against their specified values (e.g. >= 2019xx), not just whether they are defined. (For a lambda to be usable as Expr the compiler also needs to support lambdas in unevaluated contexts, but I suppose the trait doesn't technically require that.)

pdimov avatar Jun 16 '21 16:06 pdimov

Thanks for your feedback, @pdimov.

Sure, I'll update the example to more descriptive. The basic idea is just to enable C++20 style lambdas (especially with if constexpr and requires) for simplicity of usage (instead of declaring aliases).

Yeah, I was trying that but both clang and gcc didn't set the date correctly.

kris-jusiak avatar Jun 16 '21 16:06 kris-jusiak

@pdimov Updated the example. Hopefully, the update makes it more clear/descriptive. I also check again whether feature macros can be used purely without any workarounds but it seems that they always return the same standard date although the implementation differs :/

  • https://godbolt.org/z/Ga9zx4Gs8

kris-jusiak avatar Jun 16 '21 23:06 kris-jusiak

@pdimov I updated feature macros to verify the date as you suggested. I hope that works for you. Is there anything else you would like me to address? Thank you.

kris-jusiak avatar Jun 19 '21 17:06 kris-jusiak

It's fine; but I have more pressing things to do at the moment, so I'll need to come back to this later, and maybe not in time for 1.77.

pdimov avatar Jun 19 '21 22:06 pdimov

No worries @pdimov , fully understood. Thank you. Pinging, just in case you are free and/or to show that the MR isn't stale.

kris-jusiak avatar Jul 20 '21 20:07 kris-jusiak

Hey @pdimov. I know you are busy, just pinging in case you are available, no worries if not. Thanks.

kris-jusiak avatar Aug 20 '21 13:08 kris-jusiak

I sat on this for a while because I wasn't sure what I want to do with it. Adding references doesn't feel like the right thing to do, for example.

But I've now made up my mind and I don't think it belongs in the library, it's not a good fit conceptually. Sorry.

It's still cool and would make a good blog post.

pdimov avatar Aug 29 '21 11:08 pdimov