Skip to content

Lifting functions to accept and return optional values

License

Notifications You must be signed in to change notification settings

kkarbowiak/optional-lift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Optional lift

This code illustrates how to 'lift' functions in C++. Lifting is the process of transforming a function into a corresponding function in a different (usually more general) setting. The term comes from functional programming and is used in that domain extensively, but can also be useful in C++.

This particular example transforms functions of signature T (U) into functions of signature optional<T> (optional<U>). That is, if for example you have a function that takes an int and returns a std::string (like std::to_string), you can turn it into a function that takes an optional<int> and returns an optional<std::string>. An empty optional on input produces an empty optional on output. A non-empty optional on input produces a non-empty optional on output and the original function is used to transform the wrapped value.

License

This project is released under MIT/X11 license, so feel free to do anything you like with it.

About

Lifting functions to accept and return optional values

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages