fork download
  1. template<typename R, typename F> auto fold(R r, F f)
  2. -> decltype(fold(r, f, *r()))
  3. {
  4. if (auto val = r())
  5. return fold(r, f, *val);
  6. assert("Fuckbuckets.");
  7. }
  8. template<typename R, typename F, typename T> auto fold(R r, F f, T t)
  9. -> decltype(fold(r, f, *r()))
  10. {
  11. if (auto val = r())
  12. return f(t, fold(r, f, *val));
  13. return t;
  14. }
  15.  
  16. template<typename R, typename F> auto filter(R r, F f) {
  17. return [=]() -> decltype(r()) {
  18. auto val = r();
  19. if (f(*val)) return val;
  20. return std::nullopt;
  21. };
  22. }
  23.  
  24. template<typename R, typename F> auto map(R r, F f) {
  25. return [=]() -> std::optional<decltype(f(*r()))> {
  26. auto val = r();
  27. if (val) return f(*val);
  28. return std::nullopt;
  29. };
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:1: warning: identifier ‘decltype’ is a keyword in C++11 [-Wc++0x-compat]
prog.cpp:1:34: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
prog.cpp:2:4: error: expected type-specifier before ‘decltype’
prog.cpp:2:4: error: expected initializer before ‘decltype’
prog.cpp:8:46: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
prog.cpp:9:4: error: expected type-specifier before ‘decltype’
prog.cpp:9:4: error: expected initializer before ‘decltype’
prog.cpp:16:34: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
prog.cpp:16:54: error: ISO C++ forbids declaration of ‘filter’ with no type [-fpermissive]
prog.cpp:16:54: error: top-level declaration of ‘filter’ specifies ‘auto’
prog.cpp:16:54: error: storage class ‘auto’ invalid for function ‘filter’
prog.cpp: In function ‘int filter(R, F)’:
prog.cpp:17:21: error: expected type-specifier before ‘decltype’
prog.cpp: In lambda function:
prog.cpp:17:21: error: expected ‘{’ before ‘decltype’
prog.cpp:17:21: warning: no return statement in function returning non-void [-Wreturn-type]
prog.cpp: In function ‘int filter(R, F)’:
prog.cpp:17:21: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
prog.cpp:17:21: error: expected ‘;’ before ‘decltype’
prog.cpp:17:35: error: expected ‘;’ before ‘{’ token
prog.cpp: At global scope:
prog.cpp:24:34: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
prog.cpp:24:51: error: ISO C++ forbids declaration of ‘map’ with no type [-fpermissive]
prog.cpp:24:51: error: top-level declaration of ‘map’ specifies ‘auto’
prog.cpp:24:51: error: storage class ‘auto’ invalid for function ‘map’
prog.cpp: In function ‘int map(R, F)’:
prog.cpp:25:21: error: expected type-specifier
prog.cpp: In lambda function:
prog.cpp:25:21: error: expected ‘{’
prog.cpp:25:21: warning: no return statement in function returning non-void [-Wreturn-type]
prog.cpp: In function ‘int map(R, F)’:
prog.cpp:25:21: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
prog.cpp:25:21: error: expected ‘;’
prog.cpp:25:21: error: ‘optional’ is not a member of ‘std’
prog.cpp:25:54: error: expected primary-expression before ‘{’ token
prog.cpp:25:54: error: expected ‘;’ before ‘{’ token
stdout
Standard output is empty