Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h authored Jul 25, 2024
2 parents 63395ee + 73449dc commit c20a94f
Show file tree
Hide file tree
Showing 8 changed files with 985 additions and 7 deletions.
8 changes: 4 additions & 4 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 @@ -30,7 +30,7 @@ jobs:
shell: bash

steps:
- name: Add repos for for gcc-13 and clang-16
- name: Add repos for for gcc-13 and clang-16,..
uses: dice-group/cpp-conan-release-reusable-workflow/.github/actions/setup_apt@main

- name: Install CMake
Expand Down Expand Up @@ -66,7 +66,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
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ cmake_minimum_required(VERSION 3.24)

project(
dice-template-library
VERSION 1.5.1
VERSION 1.6.0
DESCRIPTION
"This template library is a collection of template-oriented code that we, the Data Science Group at UPB, found pretty handy. It contains: `switch_cases` (Use runtime values in compile-time context), `integral_template_tuple` (Create a tuple-like structure that instantiates a template for a range of values), `integral_template_variant` (A wrapper type for `std::variant` guarantees to only contain variants of the form `T<IX>` and `for_{types,values,range}` (Compile time for loops for types, values or ranges))."
HOMEPAGE_URL "https://dice-research.org/")

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
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ It contains:
- `for_{types,values,range}`: Compile time for loops for types, values or ranges
- `polymorphic_allocator`: Like `std::pmr::polymorphic_allocator` but with static dispatch
- `DICE_DEFER`/`DICE_DEFER_TO_SUCCES`/`DICE_DEFER_TO_FAIL`: On-the-fly RAII for types that do not support it natively (similar to go's `defer` keyword)
- `overloaded`: Composition for `std::variant` visitor lambdas
- `flex_array`: A combination of `std::array` and `std::span`
- `tuple_algorithms`: Some algorithms for iterating tuples
- `generator`: The reference implementation of `std::generator` from [P2502R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2502r2.pdf)

## Usage

Expand Down Expand Up @@ -71,6 +75,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 All @@ -90,7 +101,7 @@ add
FetchContent_Declare(
dice-template-library
GIT_REPOSITORY "https://github.com/dice-group/dice-template-library.git"
GIT_TAG v1.5.1
GIT_TAG v1.6.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(dice-template-library)
Expand All @@ -109,7 +120,7 @@ target_link_libraries(your_target
### conan

You can use it with [conan](https://conan.io/).
To do so, you need to add `dice-template-library/1.5.1` to the `[requires]` section of your conan file.
To do so, you need to add `dice-template-library/1.6.0` to the `[requires]` section of your conan file.

## Build and Run Tests and Examples

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<char> leaf1{'A'};
Tree<char> leaf2{'C'};
Tree<char> leaf3{'E'};
Tree<char> leaf4{'G'};
Tree<char> branch1{'B', &leaf1, &leaf2};
Tree<char> branch2{'F', &leaf3, &leaf4};
Tree<char> 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';
}
Loading

0 comments on commit c20a94f

Please sign in to comment.