Skip to content

The libspin library is based on the modern c++ design pattern, which is designed to help c++ producers design and develop at a higher level, providing better abstraction services and improving project development efficiency.

License

Notifications You must be signed in to change notification settings

slackchen/libspin

Repository files navigation

libspin

libspin_logo

自旋库是基于现代c++设计模式而产生的,目的是为了帮助c++生产者在更高层次进行设计开发,从而提供更好的抽象服务,提高项目开发效率。

代码示例

  • Promise
#include "Parttern/Promise.h"

using namespace std;

int main()
{
    auto promise = make_promise([](auto promise, auto success, auto failure){
        if (promise.status == PromiseStatus::Resolved)
        {
            for (int i = 0; i < 1000; ++i)
            {
                cout << i << endl;
            }

            success(1);
        } else
        {
            failure(2);
        }
    });

    promise.Then([](int value){

        // success
        cout << "success: " << value << endl;

    }, [](int value){

        // failure
        cout << "failure: " << value << endl;
    });

    return 0;
}
  • Maybe
using namespace std;

struct Person
{
    string* name;
};

int main()
{

    Person* p = new Person;
    p->name = new string("good boy");

    auto z = maybe(p)
        .With([](auto x) { return x->name; })
        .Do([](auto x) { cout << *x << endl; })
    ;

    return 0;
}

写在最后

如果喜欢请star,谢谢!

About

The libspin library is based on the modern c++ design pattern, which is designed to help c++ producers design and develop at a higher level, providing better abstraction services and improving project development efficiency.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published