Skip to content

voins/hanlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Why

I don't like std::optional. I mean it's cool at solving one problem: turning an undefined behavior of dereferencing a nullptr into defined behavior of dereferencing std::optional. Effectively converting SIGSEGV into an exception. But it doesn't help me make my code cleaner. I still need to check if that thing contains some value and if I fail to remember, I have a bug.

How

The pattern could be found in other languages. But the general idea is that it should be impossible to access the value without the check.

API

template <typename T> class maybe;
auto maybe<T>::then_do([](T&&) -> void { ... }) -> maybe<T>;
template <typename R>
auto maybe<T>::then_do([](T&&) -> R { ... }) -> maybe<R>;
template <typename R>
auto maybe<T>::then_maybe([](T&&) -> maybe<R> { ... }) -> maybe<R>;
auto maybe<T>::or_else(T) -> T
auto maybe<T>::or_else_do([]{ ... }) -> maybe<T>;
auto maybe<T>::or_else_do([]() -> T { ... }) -> maybe<T>;
auto maybe<T>::or_maybe([]() -> maybe<T> { ... }) -> maybe<T>;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published