Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 618 Bytes

README.md

File metadata and controls

33 lines (23 loc) · 618 Bytes

Result

Result - Simple monad solution based on C++17 and policy based design

    #include "result/result.hpp"

    #include <iostream>

    using Result = Result<int, std::string>;

    constexpr int forty_and_two{42};
    static std::string const error_string{"Bad wolf"};

    Result answer(int answer)
    {
        return forty_and_two == answer ? Result{answer} : Result{error_string};
    }

    int main()
    {
        auto ok_result = answer(forty_and_two);
        
        if(ok_result)
        {
            std::cout << ok_result.value() << '\n';
        }
    
        return 0;
    }

{}