Skip to content

duque #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed

duque #1179

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v5
- name: cmake
run: cmake -GNinja . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=On -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -Wall -Wextra -Wpedantic -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -Werror"
- name: ninja
run: ninja
- name: ninja test
run: ninja test
- uses: actions/checkout@v4
- name: Install latest available GCC
run: |
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
# 查找版本号最高的 g++ 包
LATEST_GCC_VERSION=$(apt-cache search g\+\+ | grep -oP '^g\+\+-\K[0-9]+' | sort -rn | head -n 1)
echo "Found latest GCC version: ${LATEST_GCC_VERSION}"
sudo apt-get install -y g++-${LATEST_GCC_VERSION}
# 设置新版本为默认编译器
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${LATEST_GCC_VERSION} 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${LATEST_GCC_VERSION} 100
- name: Verify GCC version
run: g++ --version
- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v5
- name: cmake
run: cmake -GNinja . -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=On -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -Wall -Wextra -Wpedantic -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion -Werror"
- name: ninja
run: ninja
- name: ninja test
run: ninja test

windows:

Expand Down
68 changes: 68 additions & 0 deletions include/fast_io_dsal/deque.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once
#undef min
#undef max

#if !defined(__cplusplus)
#error "You must be using a C++ compiler"
#endif

#include <algorithm>
#include <limits>
#include <memory>
#include <ranges>

#include "../fast_io_core_impl/freestanding/impl.h"
#include "../fast_io_core_impl/terminate.h"
#include "../fast_io_core_impl/allocation/impl.h"

#include "impl/deque.h"

#if ((__STDC_HOSTED__ == 1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED == 1) && \
!defined(_LIBCPP_FREESTANDING)) || \
defined(FAST_IO_ENABLE_HOSTED_FEATURES))

namespace fast_io {
template<typename T, typename Alloc = native_global_allocator>
using deque = containers::deque<T, Alloc>;

namespace containers {
template<::std::input_iterator U, typename V>
deque(U, V) -> deque<typename ::std::iterator_traits<U>::value_type,
generic_allocator_adapter<typename ::std::iterator_traits<U>::value_type> >;

template<::std::input_iterator U, typename V,
details::mini_alloc Alloc = generic_allocator_adapter<typename
::std::iterator_traits<
U>::value_type> >
deque(U, V, Alloc) -> deque<typename ::std::iterator_traits<U>::value_type, Alloc>;

#ifdef __cpp_lib_containers_ranges
template<::std::ranges::input_range R>
deque(::std::from_range_t, R &&)
-> deque<::std::ranges::range_value_t<R>, ::fast_io::generic_allocator_adapter<::std::ranges::range_value_t<
R> > >;

template<::std::ranges::input_range R,
::fast_io::containers::details::mini_alloc Alloc = ::fast_io::generic_allocator_adapter<
::std::ranges::range_value_t<R> > >
deque(::std::from_range_t, R &&, Alloc) -> deque<::std::ranges::range_value_t<R>, Alloc>;
#endif
template<typename T, typename Alloc, typename U = T>
inline constexpr ::std::size_t erase(deque<T, Alloc> &c, const U &value) {
auto const it = ::std::remove(c.begin(), c.end(), value);
auto const r = c.end() - it;
c.resize(c.size() - r);
return r;
}

template<typename T, typename Alloc, typename Pred>
inline constexpr ::std::size_t erase_if(deque<T, Alloc> &c, Pred pred) {
auto const it = ::std::remove_if(c.begin(), c.end(), pred);
auto const r = c.end() - it;
c.resize(c.size() - r);
return r;
}
}
}

#endif
Loading