Skip to content

seeflood/libgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libgo

I want to write cpp code in a golang style.

Usage

chan + GO

See example.cpp.

#include "libgo.hpp"
#include <iostream>
#include <optional>

class GeneratorChan : public chan {
public:
  std::optional<int> GO(
    for (; i < 10; i++) {
      WRITE_CHAN(i);
    }
  )
private:
  int i = 0;
};

int main() {
  GeneratorChan ch;
  auto data = ch();
  while(data.has_value()) {
    std::cout << data.value() << std::endl;
    data = ch();
  }

  return 0;
}

This API essentially provides a stackless coroutine.

You can run it:

g++ -std=c++17 example.cpp -o main && chmod +x main && ./main

atomic_value

See example_atomic.cpp

About

I want to write cpp code in a golang style.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages