Skip to content

Commit

Permalink
Merge pull request #1061 from trcrsired/master
Browse files Browse the repository at this point in the history
work around old version of libcxx. Support LLVM21. Remove support of LLVM20
  • Loading branch information
trcrsired authored Feb 1, 2025
2 parents 6235c08 + 3781e4f commit f27ef57
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 35 deletions.
45 changes: 45 additions & 0 deletions include/fast_io_core_impl/freestanding/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@
#pragma GCC system_header
#endif

#if __cpp_impl_three_way_comparison >= 201907L
#if __cpp_lib_three_way_comparison >= 201907L
namespace fast_io::freestanding
{
using ::std::lexicographical_compare_three_way;
using ::std::compare_three_way;
} // namespace fast_io::freestanding
#else
namespace fast_io::freestanding
{
template <typename I1, typename I2, typename Cmp>
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp)
-> decltype(comp(*f1, *f2))
{
using ret_t = decltype(comp(*f1, *f2));
static_assert(::std::disjunction_v<
::std::is_same<ret_t, ::std::strong_ordering>,
::std::is_same<ret_t, ::std::weak_ordering>,
::std::is_same<ret_t, ::std::partial_ordering>>,
"The return type must be a comparison category type.");

bool exhaust1{f1 == l1};
bool exhaust2{f2 == l2};
for (; !exhaust1 && !exhaust2; exhaust1 = (++f1 == l1), exhaust2 = (++f2 == l2))
{
if (auto c = comp(*f1, *f2); c != 0)
{
return c;
}
}

return !exhaust1 ? ::std::strong_ordering::greater : !exhaust2 ? ::std::strong_ordering::less
: ::std::strong_ordering::equal;
}

template <typename I1, typename I2>
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2)
{
return lexicographical_compare_three_way(f1, l1, f2, l2, ::std::compare_three_way{});
}

} // namespace fast_io::freestanding
#endif
#endif

#if 0
//__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1)
namespace fast_io::freestanding
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_core_impl/freestanding/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ no ::std::array, ::std::copy and others
#include "allocator.h"
#endif

#include <algorithm>

#include "noexcept_call.h"
#include "array.h"
#include "cstr_len.h"
#include "bytes.h"
#include "algorithm.h"
#include "relocatable.h"
#include "ranges.h"

#include <algorithm>
4 changes: 2 additions & 2 deletions include/fast_io_dsal/impl/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,13 @@ inline constexpr bool operator==(::fast_io::containers::array<T, N1> const &a, :
}
}

#if __cpp_lib_three_way_comparison >= 201907L
#if __cpp_impl_three_way_comparison >= 201907L

template <typename T, ::std::size_t N1, ::std::size_t N2>
requires ::std::three_way_comparable<T>
inline constexpr auto operator<=>(::fast_io::containers::array<T, N1> const &a, ::fast_io::containers::array<T, N2> const &b)
{
return ::std::lexicographical_compare_three_way(a.data(), a.data() + N1, b.data(), b.data() + N2, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.data(), a.data() + N1, b.data(), b.data() + N2, ::std::compare_three_way{});
}

#endif
Expand Down
12 changes: 6 additions & 6 deletions include/fast_io_dsal/impl/cstring_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,37 +203,37 @@ inline constexpr bool operator==(::fast_io::containers::basic_string_view<char_t
return b == a;
}

#if __cpp_lib_three_way_comparison >= 201907L
#if __cpp_impl_three_way_comparison >= 201907L
template <::std::integral char_type>
inline constexpr auto operator<=>(::fast_io::containers::basic_cstring_view<char_type> a, ::fast_io::containers::basic_cstring_view<char_type> b) noexcept
{
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
}

template <::std::integral char_type, ::std::size_t n>
inline constexpr auto operator<=>(::fast_io::containers::basic_cstring_view<char_type> a, char_type const (&buffer)[n]) noexcept
{
constexpr ::std::size_t nm1{n - 1u};
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, buffer, buffer + nm1, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, buffer, buffer + nm1, ::std::compare_three_way{});
}

template <::std::integral char_type, ::std::size_t n>
inline constexpr auto operator<=>(char_type const (&buffer)[n], ::fast_io::containers::basic_cstring_view<char_type> a) noexcept
{
constexpr ::std::size_t nm1{n - 1u};
return ::std::lexicographical_compare_three_way(buffer, buffer + nm1, a.ptr, a.ptr + a.n, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(buffer, buffer + nm1, a.ptr, a.ptr + a.n, ::std::compare_three_way{});
}

template <::std::integral char_type>
inline constexpr auto operator<=>(::fast_io::containers::basic_cstring_view<char_type> a, ::fast_io::containers::basic_string_view<char_type> b) noexcept
{
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
}

template <::std::integral char_type>
inline constexpr auto operator<=>(::fast_io::containers::basic_string_view<char_type> a, ::fast_io::containers::basic_cstring_view<char_type> b) noexcept
{
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_dsal/impl/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ template <typename T, typename allocator1, typename allocator2>
requires ::std::three_way_comparable<T>
inline constexpr auto operator<=>(deque<T, allocator1> const &lhs, deque<T, allocator2> const &rhs) noexcept
{
return ::std::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_dsal/impl/forward_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ template <typename T, typename allocator1, typename allocator2>
requires ::std::three_way_comparable<T>
inline constexpr auto operator<=>(::fast_io::containers::forward_list<T, allocator1> const &lhs, ::fast_io::containers::forward_list<T, allocator2> const &rhs) noexcept
{
return ::std::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
}

#endif
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_dsal/impl/index_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ inline constexpr bool operator==(::fast_io::containers::index_span<T, N1> a, ::f
}
}

#if __cpp_lib_three_way_comparison >= 201907L
#if __cpp_impl_three_way_comparison >= 201907L
template <typename T, ::std::size_t N1, ::std::size_t N2>
requires ::std::three_way_comparable<T>
inline constexpr auto operator<=>(::fast_io::containers::index_span<T, N1> a, ::fast_io::containers::index_span<T, N2> b)
{
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + N1, b.ptr, b.ptr + N2, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + N1, b.ptr, b.ptr + N2, ::std::compare_three_way{});
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions include/fast_io_dsal/impl/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class list
#endif
::std::conditional_t<alloc_with_status, list<T, allocator> *, allocator> v;
inline explicit constexpr new_handle_guard(::fast_io::containers::details::list_node<value_type> *p,
list<T, allocator> *va)
list<T, allocator> *va)
{
ptr = p;
if constexpr (alloc_with_status)
Expand Down Expand Up @@ -1033,13 +1033,13 @@ inline constexpr bool operator==(list<T, allocator1> const &lhs, list<T, allocat
return ::std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend());
}

#if __cpp_lib_three_way_comparison >= 201907L
#if __cpp_impl_three_way_comparison >= 201907L

template <typename T, typename allocator1, typename allocator2>
requires ::std::three_way_comparable<T>
inline constexpr auto operator<=>(list<T, allocator1> const &lhs, list<T, allocator2> const &rhs) noexcept
{
return ::std::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
}

#endif
Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_dsal/impl/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ inline constexpr bool operator==(::fast_io::containers::span<T> a, ::fast_io::co
return ::std::equal(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n);
}

#if __cpp_lib_three_way_comparison >= 201907L
#if __cpp_impl_three_way_comparison >= 201907L
template <typename T>
requires ::std::three_way_comparable<T>
inline constexpr auto operator<=>(::fast_io::containers::span<T> a, ::fast_io::containers::span<T> b)
{
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
}
#endif

Expand Down
10 changes: 5 additions & 5 deletions include/fast_io_dsal/impl/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -1524,33 +1524,33 @@ inline constexpr bool operator==(char_type const (&buffer)[n], ::fast_io::contai
template <::std::integral chtype, typename allocator1, typename allocator2>
inline constexpr auto operator<=>(::fast_io::containers::basic_string<chtype, allocator1> const &lhs, ::fast_io::containers::basic_string<chtype, allocator2> const &rhs) noexcept
{
return ::std::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
}

template <::std::integral chtype, typename allocator1>
inline constexpr auto operator<=>(::fast_io::containers::basic_string<chtype, allocator1> const &lhs, ::fast_io::containers::basic_string_view<chtype> rhs) noexcept
{
return ::std::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
}

template <::std::integral chtype, typename allocator1>
inline constexpr auto operator<=>(::fast_io::containers::basic_string_view<chtype> lhs, ::fast_io::containers::basic_string<chtype, allocator1> const &rhs) noexcept
{
return ::std::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(), ::std::compare_three_way{});
}

template <::std::integral char_type, typename allocator1, ::std::size_t n>
inline constexpr auto operator<=>(::fast_io::containers::basic_string<char_type, allocator1> a, char_type const (&buffer)[n]) noexcept
{
constexpr ::std::size_t nm1{n - 1u};
return ::std::lexicographical_compare_three_way(a.cbegin(), a.cend(), buffer, buffer + nm1, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.cbegin(), a.cend(), buffer, buffer + nm1, ::std::compare_three_way{});
}

template <::std::integral char_type, typename allocator1, ::std::size_t n>
inline constexpr auto operator<=>(char_type const (&buffer)[n], ::fast_io::containers::basic_string<char_type, allocator1> a) noexcept
{
constexpr ::std::size_t nm1{n - 1u};
return ::std::lexicographical_compare_three_way(buffer, buffer + nm1, a.cbegin(), a.cend(), ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(buffer, buffer + nm1, a.cbegin(), a.cend(), ::std::compare_three_way{});
}

#endif
Expand Down
8 changes: 4 additions & 4 deletions include/fast_io_dsal/impl/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,25 +645,25 @@ inline constexpr bool operator==(char_type const (&buffer)[n], ::fast_io::contai
return ::std::equal(buffer, buffer + nm1, a.ptr, a.ptr + a.n);
}

#if __cpp_lib_three_way_comparison >= 201907L
#if __cpp_impl_three_way_comparison >= 201907L
template <::std::integral char_type>
inline constexpr auto operator<=>(::fast_io::containers::basic_string_view<char_type> a, ::fast_io::containers::basic_string_view<char_type> b) noexcept
{
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, b.ptr, b.ptr + b.n, ::std::compare_three_way{});
}

template <::std::integral char_type, ::std::size_t n>
inline constexpr auto operator<=>(::fast_io::containers::basic_string_view<char_type> a, char_type const (&buffer)[n]) noexcept
{
constexpr ::std::size_t nm1{n - 1u};
return ::std::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, buffer, buffer + nm1, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(a.ptr, a.ptr + a.n, buffer, buffer + nm1, ::std::compare_three_way{});
}

template <::std::integral char_type, ::std::size_t n>
inline constexpr auto operator<=>(char_type const (&buffer)[n], ::fast_io::containers::basic_string_view<char_type> a) noexcept
{
constexpr ::std::size_t nm1{n - 1u};
return ::std::lexicographical_compare_three_way(buffer, buffer + nm1, a.ptr, a.ptr + a.n, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(buffer, buffer + nm1, a.ptr, a.ptr + a.n, ::std::compare_three_way{});
}

#endif
Expand Down
7 changes: 3 additions & 4 deletions include/fast_io_dsal/impl/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ class vector
auto lastele{imp.curr_ptr};
if constexpr (!::std::is_trivially_destructible_v<value_type>)
{
::std::destroy_at(it);
::std::destroy_at(it);
}
::fast_io::freestanding::uninitialized_relocate(it + 1, lastele, it);
imp.curr_ptr = lastele;
Expand Down Expand Up @@ -1054,7 +1054,6 @@ class vector
}
this->erase_iters_common(beginptr + firstidx, beginptr + lastidx);
}

};

template <typename T, typename allocator1, typename allocator2>
Expand All @@ -1064,12 +1063,12 @@ inline constexpr bool operator==(vector<T, allocator1> const &lhs, vector<T, all
return ::std::equal(lhs.imp.begin_ptr, lhs.imp.curr_ptr, rhs.imp.begin_ptr, rhs.imp.curr_ptr);
}

#if __cpp_lib_three_way_comparison >= 201907L
#if __cpp_impl_three_way_comparison >= 201907L
template <typename T, typename allocator1, typename allocator2>
requires ::std::three_way_comparable<T>
inline constexpr auto operator<=>(vector<T, allocator1> const &lhs, vector<T, allocator2> const &rhs) noexcept
{
return ::std::lexicographical_compare_three_way(lhs.imp.begin_ptr, lhs.imp.curr_ptr, rhs.imp.begin_ptr, rhs.imp.curr_ptr, ::std::compare_three_way{});
return ::fast_io::freestanding::lexicographical_compare_three_way(lhs.imp.begin_ptr, lhs.imp.curr_ptr, rhs.imp.begin_ptr, rhs.imp.curr_ptr, ::std::compare_three_way{});
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion support.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Compiler Support
- GCC >= 15
- Clang >= 20
- Clang >= 21
- MSVC

## C++ standard library support
Expand Down
4 changes: 2 additions & 2 deletions tests/0026.container/0001.vector/vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main()
print("1: {", rgvw(words1, ", "), "}\n");

// words2 == words1
fast_io::vector<std::string> words2(words1.begin(), words1.end());
fast_io::vector<std::string> words2(::std::from_range, words1);
print("2: {", rgvw(words2, ", "), "}\n");

// words3 == words1
Expand All @@ -23,6 +23,6 @@ int main()
print("4: {", rgvw(words4, ", "), "}\n");

auto const rg = {"cat", "cow", "crow"};
fast_io::vector<std::string> words5(std::from_range, rg); // overload (11)
fast_io::vector<std::string> words5(::std::from_range, rg); // overload (11)
print("5: {", rgvw(words5, ", "), "}\n");
}

0 comments on commit f27ef57

Please sign in to comment.