Skip to content

Commit c20a94f

Browse files
authored
merge develop
2 parents 63395ee + 73449dc commit c20a94f

File tree

8 files changed

+985
-7
lines changed

8 files changed

+985
-7
lines changed

.github/workflows/code_testing.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
config:
15-
- os: ubuntu-22.04
16-
compiler: clang-15
1715
- os: ubuntu-22.04
1816
compiler: clang-16
1917
- os: ubuntu-22.04
2018
compiler: clang-17
19+
- os: ubuntu-22.04
20+
compiler: clang-18
2121

2222
- os: ubuntu-22.04
2323
compiler: gcc-12
@@ -30,7 +30,7 @@ jobs:
3030
shell: bash
3131

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

3636
- name: Install CMake
@@ -66,7 +66,7 @@ jobs:
6666
uses: dice-group/cpp-conan-release-reusable-workflow/.github/actions/add_conan_provider@main
6767

6868
- name: Configure CMake
69-
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 .
69+
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 .
7070
env:
7171
CC: ${{ steps.install_cc.outputs.cc }}
7272
CXX: ${{ steps.install_cc.outputs.cxx }}

CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ cmake_minimum_required(VERSION 3.24)
22

33
project(
44
dice-template-library
5-
VERSION 1.5.1
5+
VERSION 1.6.0
66
DESCRIPTION
77
"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))."
88
HOMEPAGE_URL "https://dice-research.org/")
99

1010
option(BUILD_TESTING "build tests" OFF)
1111
option(BUILD_EXAMPLES "build examples" OFF)
1212

13+
if (PROJECT_IS_TOP_LEVEL)
14+
set(CONAN_INSTALL_ARGS "${CONAN_INSTALL_ARGS};-o=boost/*:header_only=True")
15+
endif ()
16+
1317
# conan requires cmake build type to be specified and it is generally a good idea
1418
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/CMakeCache.txt)
1519
if (NOT CMAKE_BUILD_TYPE)

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ It contains:
1010
- `for_{types,values,range}`: Compile time for loops for types, values or ranges
1111
- `polymorphic_allocator`: Like `std::pmr::polymorphic_allocator` but with static dispatch
1212
- `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)
13+
- `overloaded`: Composition for `std::variant` visitor lambdas
14+
- `flex_array`: A combination of `std::array` and `std::span`
15+
- `tuple_algorithms`: Some algorithms for iterating tuples
16+
- `generator`: The reference implementation of `std::generator` from [P2502R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2502r2.pdf)
1317

1418
## Usage
1519

@@ -71,6 +75,13 @@ Some algorithms for iterating tuples, for example `tuple_fold` a fold/reduce imp
7175
A combination of `std::array` and `std::span` where the size is either statically known or a runtime variable
7276
depending on the `extent` template parameter
7377

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

7687
Compilable code examples can be found in [examples](./examples). The example build requires the cmake
@@ -90,7 +101,7 @@ add
90101
FetchContent_Declare(
91102
dice-template-library
92103
GIT_REPOSITORY "https://github.com/dice-group/dice-template-library.git"
93-
GIT_TAG v1.5.1
104+
GIT_TAG v1.6.0
94105
GIT_SHALLOW TRUE)
95106
96107
FetchContent_MakeAvailable(dice-template-library)
@@ -109,7 +120,7 @@ target_link_libraries(your_target
109120
### conan
110121

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

114125
## Build and Run Tests and Examples
115126

examples/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ target_link_libraries(example_flex_array
5858
PRIVATE
5959
dice-template-library::dice-template-library
6060
)
61+
62+
add_executable(example_generator
63+
example_generator.cpp)
64+
target_link_libraries(example_generator
65+
PRIVATE
66+
dice-template-library::dice-template-library
67+
)

examples/example_generator.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
#include <dice/template-library/generator.hpp>
5+
6+
namespace dtl = dice::template_library;
7+
8+
template<typename T>
9+
struct Tree {
10+
T value;
11+
Tree *left = nullptr;
12+
Tree *right = nullptr;
13+
14+
[[nodiscard]] dtl::generator<T const &> traverse_inorder() const {
15+
if (left != nullptr) {
16+
co_yield dtl::ranges::elements_of(left->traverse_inorder());
17+
}
18+
19+
co_yield value;
20+
21+
if (right != nullptr) {
22+
co_yield dtl::ranges::elements_of(right->traverse_inorder());
23+
}
24+
}
25+
};
26+
27+
int main() {
28+
// D
29+
// B F
30+
// A C E G
31+
Tree<char> leaf1{'A'};
32+
Tree<char> leaf2{'C'};
33+
Tree<char> leaf3{'E'};
34+
Tree<char> leaf4{'G'};
35+
Tree<char> branch1{'B', &leaf1, &leaf2};
36+
Tree<char> branch2{'F', &leaf3, &leaf4};
37+
Tree<char> root{'D', &branch1, &branch2};
38+
39+
std::string output;
40+
for (char const x : root.traverse_inorder()) {
41+
output.push_back(x);
42+
}
43+
44+
assert(output == "ABCDEFG");
45+
std::cout << output << '\n';
46+
}

0 commit comments

Comments
 (0)