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 20, 2024
2 parents 6c30619 + 0d4f12f commit 03da630
Show file tree
Hide file tree
Showing 9 changed files with 565 additions and 21 deletions.
31 changes: 15 additions & 16 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-14
- 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: gcc-12
Expand All @@ -35,46 +35,46 @@ jobs:
# gcc-13
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
# clang-16
source /etc/os-release
# clang-16
echo "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-16 main" | sudo tee /etc/apt/sources.list.d/llvm-16.list
curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/llvm-16.gpg > /dev/null
# clang-17
echo "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-17 main" | sudo tee /etc/apt/sources.list.d/llvm-17.list
curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/llvm-17.gpg > /dev/null
sudo apt-get update -y
- name: Install CMake
uses: lukka/get-cmake@v3.24.3
uses: lukka/get-cmake@latest
with:
cmakeVersion: 3.16.9
cmakeVersion: 3.27.7

- name: Install compiler
id: install_cc
uses: rlalik/[email protected]
with:
compiler: ${{ matrix.config.compiler }}

- name: Install linker
uses: rui314/setup-mold@v1

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: install conan
- name: Install conan
shell: bash
env:
CC: ${{ steps.install_cc.outputs.cc }}
CXX: ${{ steps.install_cc.outputs.cxx }}
run: |
pip3 install "conan==1.60.1"
pip3 install "conan==1.62.0"
conan profile new --detect default
conan profile update settings.compiler.libcxx=libstdc++11 default
conan profile update env.CXXFLAGS="${CXXFLAGS}" default
conan profile update env.CMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS}" default
conan profile update env.CXX="${CXX}" default
conan profile update env.CC="${CC}" default
conan profile update settings.compiler.libcxx=libstdc++11 default
- name: Cache conan data
id: cache-conan
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.conan/data
key: tests-${{ matrix.config.os }}-${{ matrix.config.compiler }}-conan
Expand All @@ -84,7 +84,6 @@ jobs:
env:
CC: ${{ steps.install_cc.outputs.cc }}
CXX: ${{ steps.install_cc.outputs.cxx }}
CXXFLAGS: -fsanitize=undefined -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls

- name: Build tests and examples
working-directory: build
Expand Down
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.4.0
VERSION 1.5.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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ 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.

### `flex_array`
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

### Further Examples

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

## Build and Run Tests and Examples

Expand Down
9 changes: 8 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ add_executable(examples_tuple_algorithm
target_link_libraries(examples_tuple_algorithm
PRIVATE
dice-template-library::dice-template-library
)
)

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

#include <cstddef>
#include <iostream>
#include <variant>

using namespace dice::template_library;

// multidimensional-shape polymorphism without heap allocation

static constexpr size_t shape_max_dim = 2;
using shape_extents = flex_array<size_t, dynamic_extent, shape_max_dim>;

struct point {
flex_array<size_t, 0> extent;

[[nodiscard]] shape_extents get_extents() const noexcept {
return extent;
}
};

struct line {
flex_array<size_t, 1> length;

[[nodiscard]] shape_extents get_extents() const noexcept {
return length;
}
};

struct square {
flex_array<size_t, 2> width_height;

[[nodiscard]] shape_extents get_extents() const noexcept {
return width_height;
}
};

struct shape {
std::variant<point, line, square> shape_;

[[nodiscard]] shape_extents get_extents() const noexcept {
return std::visit([](auto const &sha) {
return sha.get_extents();
}, shape_);
}
};

// minimal size of static-length flex_arrays
static_assert(sizeof(point) == 1);
static_assert(sizeof(line) == sizeof(size_t));
static_assert(sizeof(square) == sizeof(size_t) * 2);

// no heap allocations on shape_extents
static_assert(sizeof(shape_extents) == sizeof(size_t) * 2 + sizeof(size_t));

void print_extents(shape const &sha) {
for (auto const ext : sha.get_extents()) {
std::cout << ext << " ";
}
}

int main() {
shape const point1{point{.extent = {}}};
shape const line1{line{.length = {12}}};
shape const square1{square{.width_height = {52, 15}}};

print_extents(point1);
print_extents(line1);
print_extents(square1);
}
Loading

0 comments on commit 03da630

Please sign in to comment.