diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-12-06 20:00:42 +0200 | 
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-12-06 20:00:42 +0200 | 
| commit | 0cef986e6958a0a6a7e94e8256b0039709aed56b (patch) | |
| tree | 54d161ff8c2028a2b7819d11b1d74f6b99d01ca3 /lib | |
| parent | 1466d2d1032db1e08a4105312f000a1c284d2889 (diff) | |
| download | fwd-0cef986e6958a0a6a7e94e8256b0039709aed56b.tar.gz fwd-0cef986e6958a0a6a7e94e8256b0039709aed56b.zip | |
add trailing closures
+ Useful for guard statements, not entirely sure about the final syntax
  but at least they're possible
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/fwdlib.hpp | 20 | 
1 files changed, 6 insertions, 14 deletions
| diff --git a/lib/fwdlib.hpp b/lib/fwdlib.hpp index 3efac61..5c52f65 100644 --- a/lib/fwdlib.hpp +++ b/lib/fwdlib.hpp @@ -10,23 +10,15 @@  using namespace std; -static void fwd_if(auto cond, auto ok, auto fail) -{ -	if (cond) -		ok(); -	else -		fail(); -} -  static void fwd_getline(auto next)  {  	if (cin.eof()) -		next(optional<string>{}); +		return next(optional<string>{});  	if (string line; getline(cin, line)) -		next(optional<string>{line}); +		return next(optional<string>{line});  	else -		next(optional<string>{}); +		return next(optional<string>{});  }  static void fwd_foreach(auto container, auto next) @@ -38,15 +30,15 @@ static void fwd_foreach(auto container, auto next)  static void fwd_some(auto option, auto ok, auto fail)  {  	if (option) -		ok(std::move(option.value())); +		return ok(std::move(option.value()));  	else -		fail(); +		return fail();  }  static void fwd_insert(auto container, auto elem, auto next)  {  	container.insert(std::move(elem)); -	next(std::move(container)); +	return next(std::move(container));  }  static void fwd_println(auto elem) | 
