3 ms·
What are you going to put in that variable? void f(); void v = f(); void g(a){return a;} v = g(v); Maybe my imagination is failing me, but I c
by Y_Y 2y ago
What are you going to put in that variable?
void f();
void v = f();
void g(a){return a;}
v = g(v);
Maybe my imagination is failing me, but I can't see how this can do much good without at least polymorphic functions.
- masklinn 2y agoThe void value. E.g. fn f() {} let mut v: () = f(); fn g(a: ()) { a } V = g(v); > Maybe my imagination is failing me, but I can't see how this can do much good without at least polymorphic functions. Sure, it doesn’t do much useful to C save make void ever so slightly less wonky.
- gpderetta 2y agotemplate<range R, regular X, invocable<range_value<R>, X> F> requires same_as<invoke_result_t<F, R, X>, X> auto fold(R&& range, F f, X accumulator) { for(auto x: range) accumulator = f(x, accumulator); return accumulator; } I can call that with a function returning a custom unit type: enum class void_t { Void }; fold(my_range, [](auto&& elem, void_t) { return Void; }, Void); But not with void: fold(my_range, [](auto&& elem, void) { return; }, void{}); which is very annoying and requires fold to special case 'void' via metaprogramming.
- remexre 2y agoTemplates already provide that useful polymorphism; template<typename T> T callWithState(auto f) { auto old = globalState; globalState = whatever(); T out = f(); globalState = old; return out; } (forgive any syntax errors, my C++ is very rusty...)