-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unary lambdas in unevaluated contexts as a replacement for ratio/exponent #176
Comments
This relates to #35, doesn't it? |
This an interesting approach however I do not see how we could provide the required minimum functionality with it. |
Which pieces are missing? Or, alternatively, what are the requirements you're trying to meet? |
I know that your example is a simplification and I have to think a bit more about it. For now, I do not clearly see how to for example construct a quantity of speed from the division of quantity of length and time. Also, I am not sure how to handle different units and their conversion ratios in an orthogonal way (i.e. |
I'll see if I can come up with a more concrete example in the next few days. I think I understand your concern |
Also related to #195. #209 (comment) implies that we'd have to drop support for Clang 12 and probably 13 too. And 14 at worst. |
There are a couple of obstacles associated with using ratios to represent conversion factors, namely:
On the contrary, allowing something like this could be an interesting thing to look into as a means of solving the above:
template<auto func> struct example_base_quantity { ... };
...
struct example_derived_quantity : example_base_quantity<[](auto&& x){ return std::sin(x); }> { ... };
What is not immediately clear to me, is how this will be optimized on various platforms. Perhaps one way to make the cost more clear is to also consider nullary lambdas that return scale factors. Nullary lambdas could simply be evaluated to a constant in the nested lambda definition. The alternative here is to hope that the compiler being used successfully flattens the recursion (I'm not convinced this would happen, but perhaps you might know the answer to this).
Another hidden advantage to this methodology is automatic type promotion. Something like this:
[](auto&& x){ return 5 * x + 32; };
returns an integer when x is an integer, and a double when x is a double.
http://open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0315r1.pdf
The text was updated successfully, but these errors were encountered: