Skip to content

Commit

Permalink
example readme and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h committed Jul 18, 2024
1 parent fc2abda commit c19e98c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/code_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
fail-fast: false
matrix:
config:
- os: ubuntu-22.04
compiler: clang-15
- os: ubuntu-22.04
compiler: clang-16
- os: ubuntu-22.04
compiler: clang-17
- os: ubuntu-22.04
compiler: clang-18

- os: ubuntu-22.04
compiler: gcc-12
Expand All @@ -33,6 +33,11 @@ jobs:
- name: Add repos for for gcc-13 and clang-16
uses: dice-group/cpp-conan-release-reusable-workflow/.github/actions/setup_apt@main

- name: Add repo for clang-18
run: |
echo "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-18 main" | sudo tee /etc/apt/sources.list.d/llvm-18.list
curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/llvm-18.gpg > /dev/null
- name: Install CMake
uses: lukka/get-cmake@latest
with:
Expand Down Expand Up @@ -66,7 +71,7 @@ jobs:
uses: dice-group/cpp-conan-release-reusable-workflow/.github/actions/add_conan_provider@main

- name: Configure CMake
run: cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=On -DBUILD_EXAMPLES=On -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCONAN_INSTALL_ARGS="--build=missing;-o=boost/*:header_only=True" -G Ninja -B build .
run: cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=On -DBUILD_EXAMPLES=On -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -G Ninja -B build .
env:
CC: ${{ steps.install_cc.outputs.cc }}
CXX: ${{ steps.install_cc.outputs.cxx }}
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ project(
option(BUILD_TESTING "build tests" OFF)
option(BUILD_EXAMPLES "build examples" OFF)

if (PROJECT_IS_TOP_LEVEL)
set(CONAN_INSTALL_ARGS "${CONAN_INSTALL_ARGS};-o=boost/*:header_only=True")
endif ()

# conan requires cmake build type to be specified and it is generally a good idea
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ Some algorithms for iterating tuples, for example `tuple_fold` a fold/reduce imp
A combination of `std::array` and `std::span` where the size is either statically known or a runtime variable
depending on the `extent` template parameter

### `generator`
The reference implementation of `std::generator` from [P2502R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2502r2.pdf).
By default, the generator and corresponding utilities are exported under the `dice::template_library::` namespace.
If you want this generator to serve as a drop in replacement for `std::generator` until it arrives
use `#define DICE_TEMPLATELIBRARY_GENERATOR_STD_COMPAT 1` before including the generator header. That will export
all generator related things under namespace `std::`.

### Further Examples

Compilable code examples can be found in [examples](./examples). The example build requires the cmake
Expand Down
7 changes: 7 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ target_link_libraries(example_flex_array
PRIVATE
dice-template-library::dice-template-library
)

add_executable(example_generator
example_generator.cpp)
target_link_libraries(example_generator
PRIVATE
dice-template-library::dice-template-library
)
46 changes: 46 additions & 0 deletions examples/example_generator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include <string>

#include <dice/template-library/generator.hpp>

namespace dtl = dice::template_library;

template<typename T>
struct Tree {
T value;
Tree *left = nullptr;
Tree *right = nullptr;

[[nodiscard]] dtl::generator<T const &> traverse_inorder() const {
if (left != nullptr) {
co_yield dtl::ranges::elements_of(left->traverse_inorder());
}

co_yield value;

if (right != nullptr) {
co_yield dtl::ranges::elements_of(right->traverse_inorder());
}
}
};

int main() {
// D
// B F
// A C E G
Tree leaf1{'A'};
Tree leaf2{'C'};
Tree leaf3{'E'};
Tree leaf4{'G'};
Tree branch1{'B', &leaf1, &leaf2};
Tree branch2{'F', &leaf3, &leaf4};
Tree root{'D', &branch1, &branch2};

std::string output;
for (char const x : root.traverse_inorder()) {
output.push_back(x);
}

assert(output == "ABCDEFG");
std::cout << output << '\n';
}

0 comments on commit c19e98c

Please sign in to comment.