4 ms·
I found myself using nil in C++ everywhere. typedef std::optional maybe; using nil = std::nullopt; Not quite the right definition, but I’m on an iPad.
by sillysaurusx 5y ago
I found myself using nil in C++ everywhere.
typedef std::optional maybe;
using nil = std::nullopt;
Not quite the right definition, but I’m on an iPad.
When you combine those with an “either” function which returns either a maybe<T> else a default T, you end up with a nice way of having default args in C++. Everything defaults to nil, then you set it to either(foo, defaultFoo()) in the body of the function.
Of course, C++ already has what it calls default arguments. But lisp has corrupted me. The defaults can’t be a function call, and the values can’t refer to other arguments, so they feel useless.
Heckin C++. I feel like programmers 80 years from now will still be yearning for an escape, whereas C++100 will still be the dominant systems programming language. Golang was a nice attempt, and so is Rust, but empirically the evidence is that (at least in AI) you can’t escape C++. The best thing to do is to just dive in.
- deleted 5y ago[deleted]
- pjmlp 5y agoNot only in AI, anything GPGPU related (just look how many ISO C++ folks are on the payroll of the big three), and all major language and GUI runtimes.
- dataflow 5y agousing nil = std::nullopt; I don't think that compiles? The right hand side is a value, not a type.
- sillysaurusx 5y agoconstexpr auto nil = std::nullopt. I was on an iPad. :)