Skip to content

Commit

Permalink
fake allocator traits for vector, update ci, fix vector::clear (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling authored Apr 21, 2023
1 parent b9b3a54 commit 15f3d57
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 152 deletions.
64 changes: 36 additions & 28 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ on:
types:
- published

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
formatting:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install clang-format
env:
DEBIAN_FRONTEND: noninteractive
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 15
sudo ./llvm.sh 16
rm llvm.sh
sudo apt-get install -y --no-install-recommends clang-format-15
sudo apt-get install -y --no-install-recommends clang-format-16
- name: Format files
run: find include test -type f -a \( -name "*.cc" -o -name "*.h" \) -print0 | xargs -0 clang-format-15 -i
run: find include test -type f -a \( -name "*.cc" -o -name "*.h" \) -print0 | xargs -0 clang-format-16 -i

- name: Check for differences
run: |
Expand All @@ -37,51 +41,55 @@ jobs:
strategy:
matrix:
config:
- name: GCC 10 Release
cxx: g++-10
cc: gcc-10
- name: GCC 11 Release
cxx: g++-11
cc: gcc-11
mode: Release
- name: GCC 10 Debug
cxx: g++-10
cc: gcc-10
- name: GCC 11 Debug
cxx: g++-11
cc: gcc-11
mode: Debug
valgrind: true
- name: Clang 15 Release
cxx: clang++-15
cc: clang-15
- name: Clang 16 Release
cxx: clang++-16
cc: clang-16
mode: Release
cxxflags: -stdlib=libc++
ldflags: -lc++abi
- name: Clang 15 Debug
cxx: clang++-15
cc: clang-15
- name: Clang 16 Debug
cxx: clang++-16
cc: clang-16
mode: Debug
fuzz: true
- key: GCC 10 Sanitizer
cxx: g++-10
cc: gcc-10
- key: GCC 11 Sanitizer
cxx: g++-11
cc: gcc-11
mode: Debug
cflags: -fsanitize=address,undefined -fno-omit-frame-pointer
cxxflags: -fsanitize=address,undefined -fno-omit-frame-pointer

env:
UBSAN_OPTIONS: halt_on_error=1:abort_on_error=1
steps:
- uses: actions/checkout@v2
- uses: seanmiddleditch/gha-setup-ninja@master
- uses: actions/checkout@v3

- name: Install Ninja
env:
DEBIAN_FRONTEND: noninteractive
run: sudo apt-get install -y --no-install-recommends ninja-build

# ==== INSTALL ====
- name: Install
if: matrix.config.cc == 'clang-15'
- name: Install Clang
if: matrix.config.cc == 'clang-16'
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 15 || sudo ./llvm.sh 15 workaround
sudo ./llvm.sh 16 || sudo ./llvm.sh 16 workaround
rm llvm.sh
sudo apt-get install -y --no-install-recommends libstdc++-12-dev libc++-15-dev libc++abi-15-dev clang-tidy-15 libunwind-15-dev llvm-15 libfuzzer-15-dev
sudo apt-get install -y --no-install-recommends libstdc++-12-dev libc++-16-dev libc++abi-16-dev clang-tidy-16 libunwind-16-dev llvm-16 libfuzzer-16-dev
# ==== BUILD ====
- name: CMake
Expand All @@ -95,7 +103,7 @@ jobs:
-DCMAKE_CXX_LINKER_FLAGS=${{ matrix.config.ldflags }}" \
-DCMAKE_CXX_EXE_LINKER_FLAGS="${{ matrix.config.ldflags }} \
-DCMAKE_BUILD_TYPE=${{ matrix.config.mode }} \
-DCISTA_ZERO_OUT=${{ matrix.config.mode == 'Debug' && matrix.config.cc == 'gcc-10' }}
-DCISTA_ZERO_OUT=${{ matrix.config.mode == 'Debug' && matrix.config.cc == 'gcc-11' }}
- name: Build
run: cmake --build build --target cista-test cista-test-single-header

Expand Down Expand Up @@ -127,15 +135,15 @@ jobs:

# ==== DISTRIBUTION ====
- name: Upload Distribution
if: matrix.config.mode == 'Release' && matrix.config.cc == 'gcc-10'
if: matrix.config.mode == 'Release' && matrix.config.cc == 'gcc-11'
uses: actions/upload-artifact@v1
with:
name: cista.h
path: build/cista.h

# ==== RELEASE ====
- name: Upload Release
if: github.event.action == 'published' && matrix.config.mode == 'Release' && matrix.config.cc == 'gcc-10'
if: github.event.action == 'published' && matrix.config.mode == 'Release' && matrix.config.cc == 'gcc-11'
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
types:
- published

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: windows-latest
Expand All @@ -23,10 +27,12 @@ jobs:
CC: cl.exe

steps:
- uses: actions/checkout@v2
- uses: seanmiddleditch/gha-setup-ninja@master
- uses: actions/checkout@v3
- uses: ilammy/msvc-dev-cmd@v1

- name: Install ninja
run: choco install ninja

- name: Build
run: |
cmake -GNinja -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.mode }}
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
-Wno-weak-vtables
-Wno-unneeded-member-function
-Wno-unused-member-function
-Wno-unsafe-buffer-usage
-Werror
)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand Down
24 changes: 24 additions & 0 deletions include/cista/allocator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <memory>

namespace cista {

template <typename T, template <typename> typename Ptr>
class allocator : public std::allocator<T> {
public:
using size_type = std::size_t;
using pointer = Ptr<T>;
using const_pointer = Ptr<T const>;

template <typename T1>
struct rebind {
using other = allocator<T1, Ptr>;
};

using std::allocator<T>::allocator;
using std::allocator<T>::allocate;
using std::allocator<T>::deallocate;
};

} // namespace cista
Empty file modified include/cista/bit_counting.h
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions include/cista/containers/pair.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <utility>

#include "cista/decay.h"
#include "cista/reflection/comparable.h"

Expand Down
49 changes: 24 additions & 25 deletions include/cista/containers/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,85 +212,84 @@ constexpr decltype(auto) apply_impl(std::index_sequence<I...>, F&& f,
return std::invoke(std::forward<F>(f), get<I>(std::forward<Tuple>(t))...);
}

template <typename F, typename Tuple>
template <typename F, typename Tuple,
typename Enable = std::enable_if_t<is_tuple_v<std::decay_t<Tuple>>>>
constexpr decltype(auto) apply(F&& f, Tuple&& t) {
return apply_impl(std::make_index_sequence<tuple_size_v<Tuple>>{},
std::forward<F>(f), std::forward<Tuple>(t));
}

template <typename F, typename Tuple, std::size_t... I>
constexpr decltype(auto) apply_impl(std::index_sequence<I...>, F&& f, Tuple&& a,
Tuple&& b) {
constexpr decltype(auto) apply_impl(std::index_sequence<I...>, F&& f,
Tuple const& a, Tuple const& b) {
return (std::invoke(std::forward<F>(f), get<I>(std::forward<Tuple>(a)),
get<I>(std::forward<Tuple>(b))),
...);
}

template <typename F, typename Tuple>
constexpr decltype(auto) apply(F&& f, Tuple&& a, Tuple&& b) {
constexpr decltype(auto) apply(F&& f, Tuple const& a, Tuple const& b) {
return apply_impl(
std::make_index_sequence<tuple_size_v<std::remove_reference_t<Tuple>>>{},
std::forward<F>(f), std::forward<Tuple>(a), std::forward<Tuple>(b));
}

template <typename T1, typename T2, std::size_t... I>
constexpr decltype(auto) eq(std::index_sequence<I...>, T1&& a, T2&& b) {
return ((get<I>(std::forward<T1>(a)) == get<I>(std::forward<T2>(b))) && ...);
constexpr decltype(auto) eq(std::index_sequence<I...>, T1 const& a,
T2 const& b) {
return ((get<I>(a) == get<I>(b)) && ...);
}

template <typename T1, typename T2>
std::enable_if_t<is_tuple_v<decay_t<T1>> && is_tuple_v<decay_t<T2>>, bool>
operator==(T1&& a, T2&& b) {
return eq(
std::make_index_sequence<tuple_size_v<std::remove_reference_t<T1>>>{},
std::forward<T1>(a), std::forward<T2>(b));
std::make_index_sequence<tuple_size_v<std::remove_reference_t<T1>>>{}, a,
b);
}

template <typename Tuple>
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator!=(Tuple&& a,
Tuple&& b) {
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator!=(Tuple const& a,
Tuple const& b) {
return !(a == b);
}

template <typename Tuple, std::size_t Index = 0U>
bool lt(Tuple&& a, Tuple&& b) {
bool lt(Tuple const& a, Tuple const& b) {
if constexpr (Index == tuple_size_v<Tuple>) {
return false;
} else {
if (get<Index>(std::forward<Tuple>(a)) <
get<Index>(std::forward<Tuple>(b))) {
if (get<Index>(a) < get<Index>(b)) {
return true;
}
if (get<Index>(std::forward<Tuple>(b)) <
get<Index>(std::forward<Tuple>(a))) {
if (get<Index>(b) < get<Index>(a)) {
return false;
}
return lt<Tuple, Index + 1U>(std::forward<Tuple>(a),
std::forward<Tuple>(b));
return lt<Tuple, Index + 1U>(a, b);
}
}

template <typename Tuple>
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator<(Tuple&& a,
Tuple&& b) {
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator<(Tuple const& a,
Tuple const& b) {
return lt(a, b);
}

template <typename Tuple>
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator<=(Tuple&& a,
Tuple&& b) {
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator<=(Tuple const& a,
Tuple const& b) {
return !(b < a);
}

template <typename Tuple>
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator>(Tuple&& a,
Tuple&& b) {
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator>(Tuple const& a,
Tuple const& b) {
return b < a;
}

template <typename Tuple>
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator>=(Tuple&& a,
Tuple&& b) {
std::enable_if_t<is_tuple_v<decay_t<Tuple>>, bool> operator>=(Tuple const& a,
Tuple const& b) {
return !(a < b);
}

Expand Down
Loading

0 comments on commit 15f3d57

Please sign in to comment.