diff --git a/src/yycc/carton/clap/manual.cpp b/src/yycc/carton/clap/manual.cpp index 092cc88..ebf03d6 100644 --- a/src/yycc/carton/clap/manual.cpp +++ b/src/yycc/carton/clap/manual.cpp @@ -2,7 +2,7 @@ #include "../termcolor.hpp" #include "../../patch/stream.hpp" #include "../../patch/format.hpp" -#include "../../patch/libcxx/stacktrace.hpp" +#include "../../patch/libcxx/enumerate.hpp" #include "../../string/op.hpp" #include "../../env.hpp" #include diff --git a/src/yycc/carton/clap/manual.hpp b/src/yycc/carton/clap/manual.hpp index a629730..925a277 100644 --- a/src/yycc/carton/clap/manual.hpp +++ b/src/yycc/carton/clap/manual.hpp @@ -38,7 +38,7 @@ namespace yycc::carton::clap::manual { private: ManualTr trctx; - const NS_YYCC_CLAP::application::Application app; + NS_YYCC_CLAP::application::Application app; NS_YYCC_TABULATE::Tabulate opt_printer; NS_YYCC_TABULATE::Tabulate var_printer; }; diff --git a/src/yycc/carton/tabulate.cpp b/src/yycc/carton/tabulate.cpp index 77bf475..fab7f36 100644 --- a/src/yycc/carton/tabulate.cpp +++ b/src/yycc/carton/tabulate.cpp @@ -2,7 +2,7 @@ #include "wcwidth.hpp" #include "../num/safe_op.hpp" #include "../patch/stream.hpp" -#include "../patch/libcxx/stacktrace.hpp" +#include "../patch/libcxx/enumerate.hpp" #include #include diff --git a/src/yycc/carton/tabulate.hpp b/src/yycc/carton/tabulate.hpp index bd0481e..7c8cb3b 100644 --- a/src/yycc/carton/tabulate.hpp +++ b/src/yycc/carton/tabulate.hpp @@ -113,7 +113,7 @@ namespace yycc::carton::tabulate { */ Tabulate(size_t n); ~Tabulate(); - YYCC_DELETE_COPY_MOVE(Tabulate) + YYCC_DEFAULT_COPY_MOVE(Tabulate) public: /** diff --git a/src/yycc/env.cpp b/src/yycc/env.cpp index 833e3a1..59e8ee8 100644 --- a/src/yycc/env.cpp +++ b/src/yycc/env.cpp @@ -1,5 +1,8 @@ #include "env.hpp" #include "macro/os_detector.hpp" +#include "string/reinterpret.hpp" +#include "num/safe_op.hpp" +#include "num/safe_cast.hpp" #include #include #include @@ -8,8 +11,6 @@ #if defined(YYCC_OS_WINDOWS) #include "encoding/windows.hpp" -#include "num/safe_op.hpp" -#include "num/safe_cast.hpp" #include "windows/winfct.hpp" #include "windows/import_guard_head.hpp" #include @@ -18,15 +19,12 @@ #include // For getting commandline argument. #include "windows/import_guard_tail.hpp" #elif defined(YYCC_OS_LINUX) -#include "string/reinterpret.hpp" #include #include #include // For reading commandline argument. #include #include // For reading symlink target. #elif defined(YYCC_OS_MACOS) -#include "string/reinterpret.hpp" -#include "num/safe_cast.hpp" #include #include #include @@ -331,7 +329,7 @@ namespace yycc::env { #elif defined(YYCC_OS_LINUX) // Reference: https://www.man7.org/linux/man-pages/man5/proc_pid_exe.5.html auto target = read_symlink_target("/proc/self/exe"); - if () return rv = std::move(target.value()); + if (target.has_value()) return rv = std::move(target.value()); else return std::unexpected(PathError::SysCall); #elif defined(YYCC_OS_MACOS) // TODO: This is AI generated and don't have test and reference. @@ -388,7 +386,7 @@ namespace yycc::env { class CommandLineArgvDeleter { public: CommandLineArgvDeleter() {} - void operator()(LPWSTR* ptr) { + void operator()(LPWSTR *ptr) { if (ptr != nullptr) { LocalFree(ptr); } diff --git a/src/yycc/panic.cpp b/src/yycc/panic.cpp index 06a5310..27e6b99 100644 --- a/src/yycc/panic.cpp +++ b/src/yycc/panic.cpp @@ -1,11 +1,16 @@ #include "panic.hpp" +#include "macro/stl_detector.hpp" #include "carton/termcolor.hpp" #include "patch/stream.hpp" -#include "patch/libcxx/stacktrace.hpp" #include #include #include + +#if defined(YYCC_STL_CLANGSTL) +#include "patch/libcxx/stacktrace.hpp" +#else #include +#endif #define TERMCOLOR ::yycc::carton::termcolor diff --git a/src/yycc/patch/libcxx/enumerate.hpp b/src/yycc/patch/libcxx/enumerate.hpp index cb5fb96..8c1fbc1 100644 --- a/src/yycc/patch/libcxx/enumerate.hpp +++ b/src/yycc/patch/libcxx/enumerate.hpp @@ -14,238 +14,99 @@ #include #include #include +#include -namespace std { +namespace std::ranges::views { -namespace ranges { -namespace views { + // 简化的enumerate实现 + namespace detail { -namespace detail { + template + class enumerate_view { + private: + R _range; + size_t _start; -template -concept can_reference = requires { typename T&; }; + template + class iterator { + using Base = conditional_t; + using Iter = decltype(std::ranges::begin(std::declval())); -template -concept enumerable = - ranges::input_range && - integral && - ranges::view; + Iter _iter; + size_t _index; -} // namespace detail + public: + using iterator_category = typename std::iterator_traits::iterator_category; + using value_type = std::tuple; + using difference_type = typename std::iterator_traits::difference_type; -// enumerate_view实现 -template -requires detail::enumerable -class enumerate_view : public ranges::view_interface> { -private: - V _base; - I _start; + iterator(Iter iter, size_t index) : _iter(iter), _index(index) {} - // 迭代器实现 - template - class iterator { - private: - using Base = conditional_t; - using Parent = conditional_t; - - Parent* _parent = nullptr; - ranges::iterator_t _current; - I _index; - - public: - using iterator_category = typename iterator_traits>::iterator_category; - using iterator_concept = iterator_category; - using value_type = tuple>; - using difference_type = ranges::range_difference_t; - - iterator() = default; - - constexpr iterator(Parent* parent, ranges::iterator_t current, I index) - : _parent(parent), _current(current), _index(index) {} - - constexpr iterator(iterator other) requires Const && - convertible_to, ranges::iterator_t> - : _parent(other._parent), _current(other._current), _index(other._index) {} - - constexpr ranges::iterator_t base() const { - return _current; - } - - constexpr auto operator*() const { - return tuple>(_index, *_current); - } - - constexpr iterator& operator++() { - ++_current; - ++_index; - return *this; - } - - constexpr iterator operator++(int) { - auto tmp = *this; - ++*this; - return tmp; - } - - constexpr iterator& operator--() requires ranges::bidirectional_range { - --_current; - --_index; - return *this; - } - - constexpr iterator operator--(int) requires ranges::bidirectional_range { - auto tmp = *this; - --*this; - return tmp; - } - - constexpr iterator& operator+=(difference_type n) - requires ranges::random_access_range { - _current += n; - _index += static_cast(n); - return *this; - } - - constexpr iterator& operator-=(difference_type n) - requires ranges::random_access_range { - _current -= n; - _index -= static_cast(n); - return *this; - } - - constexpr auto operator[](difference_type n) const - requires ranges::random_access_range { - return tuple>( - _index + static_cast(n), _current[n]); - } - - friend constexpr bool operator==(const iterator& x, const iterator& y) { - return x._current == y._current; - } - - friend constexpr bool operator<(const iterator& x, const iterator& y) - requires ranges::random_access_range { - return x._current < y._current; - } - - friend constexpr bool operator>(const iterator& x, const iterator& y) - requires ranges::random_access_range { - return x._current > y._current; - } - - friend constexpr bool operator<=(const iterator& x, const iterator& y) - requires ranges::random_access_range { - return x._current <= y._current; - } - - friend constexpr bool operator>=(const iterator& x, const iterator& y) - requires ranges::random_access_range { - return x._current >= y._current; - } - - friend constexpr iterator operator+(const iterator& i, difference_type n) - requires ranges::random_access_range { - auto r = i; - r += n; - return r; - } - - friend constexpr iterator operator+(difference_type n, const iterator& i) - requires ranges::random_access_range { - return i + n; - } - - friend constexpr iterator operator-(const iterator& i, difference_type n) - requires ranges::random_access_range { - auto r = i; - r -= n; - return r; - } - - friend constexpr difference_type operator-(const iterator& x, const iterator& y) - requires ranges::random_access_range { - return x._current - y._current; - } - }; - -public: - enumerate_view() = default; - - constexpr enumerate_view(V base, I start = 0) - : _base(std::move(base)), _start(start) {} - - constexpr V base() const & requires copy_constructible { - return _base; - } - - constexpr V base() && { - return std::move(_base); - } - - constexpr I start() const { - return _start; - } - - constexpr auto begin() requires (!ranges::simple_view) { - return iterator(this, ranges::begin(_base), _start); - } - - constexpr auto begin() const requires ranges::range { - return iterator(this, ranges::begin(_base), _start); - } - - constexpr auto end() requires (!ranges::simple_view) { - return iterator(this, ranges::end(_base), - _start + static_cast(ranges::distance(_base))); - } - - constexpr auto end() const requires ranges::range { - return iterator(this, ranges::end(_base), - _start + static_cast(ranges::distance(_base))); - } - - constexpr auto size() requires ranges::sized_range { - return ranges::size(_base); - } - - constexpr auto size() const requires ranges::sized_range { - return ranges::size(_base); - } -}; + auto operator*() const { return std::tuple(_index, *_iter); } -// 推导指引 -template -enumerate_view(R&&, I) -> enumerate_view, I>; + iterator& operator++() { + ++_iter; + ++_index; + return *this; + } -template -enumerate_view(R&&) -> enumerate_view, size_t>; + iterator operator++(int) { + auto tmp = *this; + ++*this; + return tmp; + } -// enumerate适配器对象 -struct enumerate_fn { - template - requires detail::enumerable, I> - constexpr auto operator()(R&& r, I start = 0) const { - return enumerate_view(views::all(forward(r)), start); - } - - template - constexpr auto operator()(I start = 0) const { - return ranges::views::__adaptor_invoke(*this, start); - } -}; + bool operator==(const iterator& other) const { return _iter == other._iter; } -// 适配器对象实例 -inline constexpr enumerate_fn enumerate; + bool operator!=(const iterator& other) const { return _iter != other._iter; } -} // namespace views + // 支持双向迭代 + iterator& operator--() + requires std::bidirectional_iterator + { + --_iter; + --_index; + return *this; + } -// 使enumerate_view成为view -template -inline constexpr bool enable_borrowed_range> = - ranges::enable_borrowed_range; + iterator operator--(int) + requires std::bidirectional_iterator + { + auto tmp = *this; + --*this; + return tmp; + } + }; -} // namespace ranges + public: + enumerate_view(R range, size_t start = 0) : _range(std::move(range)), _start(start) {} -} // namespace std + auto begin() { return iterator(std::ranges::begin(_range), _start); } + auto end() { return iterator(std::ranges::end(_range), _start + std::ranges::distance(_range)); } + + auto begin() const { return iterator(std::ranges::begin(_range), _start); } + auto end() const { return iterator(std::ranges::end(_range), _start + std::ranges::distance(_range)); } + }; + + // 适配器函数对象 + struct enumerate_fn { + template + auto operator()(R&& r, size_t start = 0) const { + return enumerate_view>(std::forward(r), start); + } + + // 用于管道操作符的版本 + auto operator()(size_t start = 0) const { + return [start](auto&& r) { + return enumerate_view>(std::forward(r), start); + }; + } + }; + + } // namespace detail + + inline constexpr detail::enumerate_fn enumerate; + +} // namespace std::ranges::views #endif