-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
565 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.