Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h authored Mar 4, 2024
2 parents 919e165 + f0ccc09 commit 6c30619
Show file tree
Hide file tree
Showing 9 changed files with 958 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22)

project(
dice-template-library
VERSION 1.3.0
VERSION 1.4.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/")
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ The primary use-case for this is on-the-fly RAII-like resource management for ty
Usage examples can be found [here](examples/examples_defer.cpp).


### `tuple algorthims`
Some algorithms for iterating tuples, for example `tuple_fold` a fold/reduce implementation for tuples.

### Further Examples

Compilable code examples can be found in [examples](./examples). The example build requires the cmake
Expand All @@ -83,7 +86,7 @@ add
FetchContent_Declare(
dice-template-library
GIT_REPOSITORY "https://github.com/dice-group/dice-template-library.git"
GIT_TAG v1.3.0
GIT_TAG v1.4.0
GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(dice-template-library)
Expand All @@ -102,7 +105,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.3.0` to the `[requires]` section of your conan file.
To do so, you need to add `dice-template-library/1.4.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 @@ -43,4 +43,11 @@ add_executable(examples_defer
target_link_libraries(examples_defer
PRIVATE
dice-template-library::dice-template-library
)

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

#include <cassert>
#include <iostream>
#include <limits>
#include <tuple>

void tuple_fold() {
std::tuple<int, double, float, long> tup{5, 1.2, 1.3F, 1L};

auto const sum = dice::template_library::tuple_fold(tup, 0L, [](auto acc, auto x) {
return acc + static_cast<long>(x);
});

assert(sum == 8);
}

void tuple_type_fold() {
using tuple_t = std::tuple<int, long>;

auto const digits_sum = dice::template_library::tuple_type_fold<tuple_t>(0UL, []<typename T>(auto acc) {
return acc + std::numeric_limits<T>::digits10;
});

assert(digits_sum == 27);
}

void tuple_for_each() {
std::tuple<int, double, float> tup{1, 1.0, 1.0F};

dice::template_library::tuple_for_each(tup, [](auto &x) {
x += 1;
});

assert((tup == std::tuple<int, double, float>{2, 2.0, 2.0F}));
}

void tuple_type_for_each() {
using tuple_t = std::tuple<int, double, float>;

dice::template_library::tuple_type_for_each<tuple_t>([&]<typename T>() {
std::cout << typeid(T).name() << '\n';
});
}

int main() {
tuple_fold();
tuple_type_fold();
tuple_for_each();
tuple_type_for_each();
}
Loading

0 comments on commit 6c30619

Please sign in to comment.