fix: fix clang compile error
- fix the include of stacktrace error. - fix env include issues. - fix wrong include for libcxx enumerate patch. - fix libcxx enumerate patch build issue. - re-add default move and copy ctor for tabulate class. - remove const decorator for clap manual member to resolve default ctor error.
This commit is contained in:
@@ -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 <ranges>
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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 <stdexcept>
|
||||
#include <ranges>
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace yycc::carton::tabulate {
|
||||
*/
|
||||
Tabulate(size_t n);
|
||||
~Tabulate();
|
||||
YYCC_DELETE_COPY_MOVE(Tabulate)
|
||||
YYCC_DEFAULT_COPY_MOVE(Tabulate)
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -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 <string>
|
||||
#include <string_view>
|
||||
#include <memory>
|
||||
@@ -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 <Windows.h>
|
||||
@@ -18,15 +19,12 @@
|
||||
#include <shellapi.h> // For getting commandline argument.
|
||||
#include "windows/import_guard_tail.hpp"
|
||||
#elif defined(YYCC_OS_LINUX)
|
||||
#include "string/reinterpret.hpp"
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
#include <fstream> // For reading commandline argument.
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h> // For reading symlink target.
|
||||
#elif defined(YYCC_OS_MACOS)
|
||||
#include "string/reinterpret.hpp"
|
||||
#include "num/safe_cast.hpp"
|
||||
#include <cstdlib>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 <cstdlib>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
#if defined(YYCC_STL_CLANGSTL)
|
||||
#include "patch/libcxx/stacktrace.hpp"
|
||||
#else
|
||||
#include <stacktrace>
|
||||
#endif
|
||||
|
||||
#define TERMCOLOR ::yycc::carton::termcolor
|
||||
|
||||
|
||||
@@ -14,238 +14,99 @@
|
||||
#include <utility>
|
||||
#include <tuple>
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
namespace std {
|
||||
namespace std::ranges::views {
|
||||
|
||||
namespace ranges {
|
||||
namespace views {
|
||||
// 简化的enumerate实现
|
||||
namespace detail {
|
||||
|
||||
namespace detail {
|
||||
template<typename R>
|
||||
class enumerate_view {
|
||||
private:
|
||||
R _range;
|
||||
size_t _start;
|
||||
|
||||
template<typename T>
|
||||
concept can_reference = requires { typename T&; };
|
||||
template<bool Const>
|
||||
class iterator {
|
||||
using Base = conditional_t<Const, const R, R>;
|
||||
using Iter = decltype(std::ranges::begin(std::declval<Base&>()));
|
||||
|
||||
template<typename V, typename I>
|
||||
concept enumerable =
|
||||
ranges::input_range<V> &&
|
||||
integral<I> &&
|
||||
ranges::view<V>;
|
||||
Iter _iter;
|
||||
size_t _index;
|
||||
|
||||
} // namespace detail
|
||||
public:
|
||||
using iterator_category = typename std::iterator_traits<Iter>::iterator_category;
|
||||
using value_type = std::tuple<size_t, decltype(*_iter)>;
|
||||
using difference_type = typename std::iterator_traits<Iter>::difference_type;
|
||||
|
||||
// enumerate_view实现
|
||||
template<ranges::view V, typename I = size_t>
|
||||
requires detail::enumerable<V, I>
|
||||
class enumerate_view : public ranges::view_interface<enumerate_view<V, I>> {
|
||||
private:
|
||||
V _base;
|
||||
I _start;
|
||||
iterator(Iter iter, size_t index) : _iter(iter), _index(index) {}
|
||||
|
||||
// 迭代器实现
|
||||
template<bool Const>
|
||||
class iterator {
|
||||
private:
|
||||
using Base = conditional_t<Const, const V, V>;
|
||||
using Parent = conditional_t<Const, const enumerate_view, enumerate_view>;
|
||||
|
||||
Parent* _parent = nullptr;
|
||||
ranges::iterator_t<Base> _current;
|
||||
I _index;
|
||||
|
||||
public:
|
||||
using iterator_category = typename iterator_traits<ranges::iterator_t<Base>>::iterator_category;
|
||||
using iterator_concept = iterator_category;
|
||||
using value_type = tuple<I, ranges::range_reference_t<Base>>;
|
||||
using difference_type = ranges::range_difference_t<Base>;
|
||||
|
||||
iterator() = default;
|
||||
|
||||
constexpr iterator(Parent* parent, ranges::iterator_t<Base> current, I index)
|
||||
: _parent(parent), _current(current), _index(index) {}
|
||||
|
||||
constexpr iterator(iterator<!Const> other) requires Const &&
|
||||
convertible_to<ranges::iterator_t<V>, ranges::iterator_t<Base>>
|
||||
: _parent(other._parent), _current(other._current), _index(other._index) {}
|
||||
|
||||
constexpr ranges::iterator_t<Base> base() const {
|
||||
return _current;
|
||||
}
|
||||
|
||||
constexpr auto operator*() const {
|
||||
return tuple<I, ranges::range_reference_t<Base>>(_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<Base> {
|
||||
--_current;
|
||||
--_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr iterator operator--(int) requires ranges::bidirectional_range<Base> {
|
||||
auto tmp = *this;
|
||||
--*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
constexpr iterator& operator+=(difference_type n)
|
||||
requires ranges::random_access_range<Base> {
|
||||
_current += n;
|
||||
_index += static_cast<I>(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr iterator& operator-=(difference_type n)
|
||||
requires ranges::random_access_range<Base> {
|
||||
_current -= n;
|
||||
_index -= static_cast<I>(n);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr auto operator[](difference_type n) const
|
||||
requires ranges::random_access_range<Base> {
|
||||
return tuple<I, ranges::range_reference_t<Base>>(
|
||||
_index + static_cast<I>(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<Base> {
|
||||
return x._current < y._current;
|
||||
}
|
||||
|
||||
friend constexpr bool operator>(const iterator& x, const iterator& y)
|
||||
requires ranges::random_access_range<Base> {
|
||||
return x._current > y._current;
|
||||
}
|
||||
|
||||
friend constexpr bool operator<=(const iterator& x, const iterator& y)
|
||||
requires ranges::random_access_range<Base> {
|
||||
return x._current <= y._current;
|
||||
}
|
||||
|
||||
friend constexpr bool operator>=(const iterator& x, const iterator& y)
|
||||
requires ranges::random_access_range<Base> {
|
||||
return x._current >= y._current;
|
||||
}
|
||||
|
||||
friend constexpr iterator operator+(const iterator& i, difference_type n)
|
||||
requires ranges::random_access_range<Base> {
|
||||
auto r = i;
|
||||
r += n;
|
||||
return r;
|
||||
}
|
||||
|
||||
friend constexpr iterator operator+(difference_type n, const iterator& i)
|
||||
requires ranges::random_access_range<Base> {
|
||||
return i + n;
|
||||
}
|
||||
|
||||
friend constexpr iterator operator-(const iterator& i, difference_type n)
|
||||
requires ranges::random_access_range<Base> {
|
||||
auto r = i;
|
||||
r -= n;
|
||||
return r;
|
||||
}
|
||||
|
||||
friend constexpr difference_type operator-(const iterator& x, const iterator& y)
|
||||
requires ranges::random_access_range<Base> {
|
||||
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<V> {
|
||||
return _base;
|
||||
}
|
||||
|
||||
constexpr V base() && {
|
||||
return std::move(_base);
|
||||
}
|
||||
|
||||
constexpr I start() const {
|
||||
return _start;
|
||||
}
|
||||
|
||||
constexpr auto begin() requires (!ranges::simple_view<V>) {
|
||||
return iterator<false>(this, ranges::begin(_base), _start);
|
||||
}
|
||||
|
||||
constexpr auto begin() const requires ranges::range<const V> {
|
||||
return iterator<true>(this, ranges::begin(_base), _start);
|
||||
}
|
||||
|
||||
constexpr auto end() requires (!ranges::simple_view<V>) {
|
||||
return iterator<false>(this, ranges::end(_base),
|
||||
_start + static_cast<I>(ranges::distance(_base)));
|
||||
}
|
||||
|
||||
constexpr auto end() const requires ranges::range<const V> {
|
||||
return iterator<true>(this, ranges::end(_base),
|
||||
_start + static_cast<I>(ranges::distance(_base)));
|
||||
}
|
||||
|
||||
constexpr auto size() requires ranges::sized_range<V> {
|
||||
return ranges::size(_base);
|
||||
}
|
||||
|
||||
constexpr auto size() const requires ranges::sized_range<const V> {
|
||||
return ranges::size(_base);
|
||||
}
|
||||
};
|
||||
auto operator*() const { return std::tuple<size_t, decltype(*_iter)>(_index, *_iter); }
|
||||
|
||||
// 推导指引
|
||||
template<class R, class I>
|
||||
enumerate_view(R&&, I) -> enumerate_view<views::all_t<R>, I>;
|
||||
iterator& operator++() {
|
||||
++_iter;
|
||||
++_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class R>
|
||||
enumerate_view(R&&) -> enumerate_view<views::all_t<R>, size_t>;
|
||||
iterator operator++(int) {
|
||||
auto tmp = *this;
|
||||
++*this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// enumerate适配器对象
|
||||
struct enumerate_fn {
|
||||
template<ranges::viewable_range R, typename I = size_t>
|
||||
requires detail::enumerable<views::all_t<R>, I>
|
||||
constexpr auto operator()(R&& r, I start = 0) const {
|
||||
return enumerate_view(views::all(forward<R>(r)), start);
|
||||
}
|
||||
|
||||
template<typename I = size_t>
|
||||
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>
|
||||
{
|
||||
--_iter;
|
||||
--_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 使enumerate_view成为view
|
||||
template<typename V, typename I>
|
||||
inline constexpr bool enable_borrowed_range<views::enumerate_view<V, I>> =
|
||||
ranges::enable_borrowed_range<V>;
|
||||
iterator operator--(int)
|
||||
requires std::bidirectional_iterator<Iter>
|
||||
{
|
||||
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<false>(std::ranges::begin(_range), _start); }
|
||||
auto end() { return iterator<false>(std::ranges::end(_range), _start + std::ranges::distance(_range)); }
|
||||
|
||||
auto begin() const { return iterator<true>(std::ranges::begin(_range), _start); }
|
||||
auto end() const { return iterator<true>(std::ranges::end(_range), _start + std::ranges::distance(_range)); }
|
||||
};
|
||||
|
||||
// 适配器函数对象
|
||||
struct enumerate_fn {
|
||||
template<std::ranges::range R>
|
||||
auto operator()(R&& r, size_t start = 0) const {
|
||||
return enumerate_view<std::ranges::views::all_t<R>>(std::forward<R>(r), start);
|
||||
}
|
||||
|
||||
// 用于管道操作符的版本
|
||||
auto operator()(size_t start = 0) const {
|
||||
return [start](auto&& r) {
|
||||
return enumerate_view<std::ranges::views::all_t<decltype(r)>>(std::forward<decltype(r)>(r), start);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline constexpr detail::enumerate_fn enumerate;
|
||||
|
||||
} // namespace std::ranges::views
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user