conduit is an educational/experimental library for coroutines as they were introduced in C++20. While I hope that this library will prove useful to the community.
Conduit can be added to an existing git repository by running
git submodule add https://github.com/functionalperez/conduit.git
This will add conduit as a submodule of your project, and whenever anyone clones your project via git clone --recursive <Your Project>
, conduit will be automatically downloaded as well.
If you're taking this route and your project uses cmake, just add this line to your CMakeLists.txt
folder and the compiler will find conduit:
add_subdirectory(conduit)
In order to ensure that your system is set up correctly, it's recommended to compile and run main.cpp
, which contains tests for conduit.
# Download
git clone https://github.com/functionalperez/conduit.git
# Build
cd conduit
mkdir build
cd build
cmake .. -DCMAKE_CXX_COMPILER=clang++
cmake --build .
# Run
./run_tests
Alternatively, if you don't want to use CMake, just run the following commands in the root directory of this project:
g++-10 -Iinclude -fcoroutines -std=c++20 main.cpp -o run_example
./run_example
You can install Conduit on a system-wide basis, and this will allow you to use conduit in C++ projects without adding any additional compiler flags and without adding anything to your build file (although you'll still need to compile your project for C++20).
In order to install conduit via cmake, run the following commands in the root directory of this project:
mkdir -p build
cd build
cmake .. -DCMAKE_CXX_COMPILER=clang++
cmake --install .
# Optionally, you can remove the repository once you've installed it:
cd ../..
rm -rf conduit
On Ubuntu, installation would be as follows:
- Download conduit.deb from the assets section of the most recent release
- Go to your downloads folder (
cd ~/Downloads
) - Run
sudo apt install ./conduit.deb
(or just double-click the file to open it in the installer)
This will install Conduit in /usr/local/include
, and Conduit can be uninstalled at any time by running sudo apt remove conduit
.
Conduit can also be installed manually by running:
git clone https://github.com/functionalperez/conduit.git
sudo cp -r conduit/include/conduit /usr/local/include
# Optionally, remove the repo after installation as it's no longer needed
rm -rf conduit
To uninstall manually, simply run
sudo rm -r /usr/local/include/conduit
Once you've installed Conduit, you can use it as you would any other installed library:
// main.cpp
#include <conduit/coroutine.hpp>
#include <conduit/generator.hpp>
#include <string>
#include <iostream>
using namespace conduit;
generator<char> hello_message() {
for(char c : "Hello, world!") {
co_yield c;
}
}
int main() {
for(char c : hello_message()) {
std::cout << c;
}
std::cout << std::endl;
}
clang++ main.cpp -std=c++20 -o main