Skip to content

Commit

Permalink
replace std::tuple with wjr::tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Jun 14, 2024
1 parent 4aa855d commit c133507
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 107 deletions.
21 changes: 5 additions & 16 deletions include/wjr/compressed_pair.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#ifndef WJR_COMPRESSED_PAIR_HPP__
#define WJR_COMPRESSED_PAIR_HPP__

#include <tuple>

#include <wjr/capture_leaf.hpp>
#include <wjr/math/integral_constant.hpp>
#include <wjr/tuple.hpp>

namespace wjr {

Expand Down Expand Up @@ -206,8 +203,8 @@ class WJR_EMPTY_BASES compressed_pair final : __compressed_pair_base1<T, U>,

template <typename... Args1, typename... Args2>
constexpr compressed_pair(
std::piecewise_construct_t, std::tuple<Args1...> tp1,
std::tuple<Args2...>
std::piecewise_construct_t, tuple<Args1...> tp1,
tuple<Args2...>
tp2) noexcept(noexcept(compressed_pair(tp1, tp2,
std::index_sequence_for<Args1...>{},
std::index_sequence_for<Args2...>{})))
Expand Down Expand Up @@ -312,20 +309,12 @@ class WJR_EMPTY_BASES compressed_pair final : __compressed_pair_base1<T, U>,

template <size_t I, WJR_REQUIRES(I < 2)>
constexpr std::tuple_element_t<I, compressed_pair> &&get() && noexcept {
if constexpr (I == 0) {
return std::move(first());
} else {
return std::move(second());
}
return static_cast<std::tuple_element_t<I, compressed_pair> &&>(get());
}

template <size_t I, WJR_REQUIRES(I < 2)>
constexpr const std::tuple_element_t<I, compressed_pair> &&get() const && noexcept {
if constexpr (I == 0) {
return std::move(first());
} else {
return std::move(second());
}
return static_cast<const std::tuple_element_t<I, compressed_pair> &&>(get());
}

template <size_t I, WJR_REQUIRES(I >= 0 && I < 2)>
Expand Down
10 changes: 4 additions & 6 deletions include/wjr/container/generic/bplus_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,10 @@ class basic_bplus_tree {
basic_bplus_tree(basic_bplus_tree &&other) noexcept(
std::is_nothrow_move_constructible_v<key_compare>
&&std::is_nothrow_move_constructible_v<_Alty>)
: m_pair(std::piecewise_construct,
std::forward_as_tuple(std::move(other.key_comp())),
std::forward_as_tuple(
std::piecewise_construct,
std::forward_as_tuple(std::move(other.__get_allocator())),
std::forward_as_tuple())) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(std::move(other.key_comp())),
wjr::forward_as_tuple(std::piecewise_construct,
wjr::forward_as_tuple(std::move(other.__get_allocator())),
wjr::forward_as_tuple())) {
__take_tree(std::move(other));
}

Expand Down
40 changes: 20 additions & 20 deletions include/wjr/container/generic/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,28 +990,28 @@ class basic_vector {

WJR_CONSTEXPR20 explicit basic_vector(const allocator_type &al) noexcept(
std::is_nothrow_constructible_v<_Alty, const allocator_type &>)
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {}
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {}

WJR_CONSTEXPR20 explicit basic_vector(const size_type n,
const allocator_type &al = allocator_type())
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
__construct_n(n, vctor);
}

WJR_CONSTEXPR20 basic_vector(size_type n, const value_type &val,
const allocator_type &al = allocator_type())
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
__construct_n(n, val);
}

private:
template <typename _Alloc>
WJR_CONSTEXPR20 basic_vector(const basic_vector &other, _Alloc &&al, in_place_empty_t)
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
const auto size = other.size();
uninitialized_construct(size, other.capacity());
STraits::uninitialized_copy_n_restrict_using_allocator(other.data(), size, data(),
Expand All @@ -1023,8 +1023,8 @@ class basic_vector {
basic_vector(basic_vector &&other, _Alloc &&al, in_place_empty_t) noexcept(
std::is_nothrow_constructible_v<storage_type, _Alloc &&>
&&__storage_noexcept_take_storage)
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
__take_storage(std::move(other));
}

Expand All @@ -1050,8 +1050,8 @@ class basic_vector {
template <typename Iter, WJR_REQUIRES(is_iterator_v<Iter>)>
WJR_CONSTEXPR20 basic_vector(Iter first, Iter last,
const allocator_type &al = allocator_type())
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
__range_construct(try_to_address(first), try_to_address(last),
iterator_category_t<Iter>());
}
Expand Down Expand Up @@ -1135,12 +1135,12 @@ class basic_vector {

WJR_PURE WJR_CONSTEXPR20 pointer __get_pointer(iterator ptr) const noexcept {
ptr.check_same_container(this);
return (to_address)(ptr);
return wjr::to_address(ptr);
}

WJR_PURE WJR_CONSTEXPR20 pointer __get_pointer(const_iterator ptr) const noexcept {
ptr.check_same_container(this);
return const_cast<pointer>((to_address)(ptr));
return const_cast<pointer>(wjr::to_address(ptr));
}

public:
Expand Down Expand Up @@ -1412,22 +1412,22 @@ class basic_vector {

WJR_CONSTEXPR20 basic_vector(size_type n, dctor_t,
const allocator_type &al = allocator_type())
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
__construct_n(n, dctor);
}

WJR_CONSTEXPR20 basic_vector(size_type n, in_place_reserve_t,
const allocator_type &al = allocator_type())
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
uninitialized_construct(0, n);
}

WJR_CONSTEXPR20 basic_vector(storage_type &&other,
const allocator_type &al = allocator_type())
: m_pair(std::piecewise_construct, std::forward_as_tuple(al),
std::forward_as_tuple()) {
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
take_storage(other);
}

Expand Down
27 changes: 14 additions & 13 deletions include/wjr/math/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#include <wjr/math/convert-impl.hpp>
#include <wjr/math/div.hpp>
#include <wjr/math/precompute-chars-convert.hpp>
#include <wjr/memory/copy.hpp>
#include <wjr/math/stack_allocator.hpp>
#include <wjr/memory/copy.hpp>


#if defined(WJR_X86)
#include <wjr/x86/math/convert.hpp>
Expand Down Expand Up @@ -978,7 +979,7 @@ uint8_t *__fast_to_chars_backward_unchecked_impl(uint8_t *ptr, Value val, IBase
template <typename Iter, typename Value, typename IBase, typename Converter>
Iter __to_chars_backward_unchecked_impl(Iter first, Value val, IBase ibase,
Converter conv) noexcept {
const auto __ptr = reinterpret_cast<uint8_t *>((to_address)(first));
const auto __ptr = reinterpret_cast<uint8_t *>(wjr::to_address(first));
const auto __end = __fast_to_chars_backward_unchecked_impl(__ptr, val, ibase, conv);
return first + std::distance(__ptr, __end);
}
Expand Down Expand Up @@ -1243,8 +1244,8 @@ template <typename Iter, typename Value, typename IBase, typename Converter>
to_chars_result<Iter> __to_chars_impl(Iter first, Iter last, Value val, IBase ibase,
Converter conv) noexcept {
if constexpr (convert_details::__is_fast_convert_iterator_v<Iter>) {
const auto __first = reinterpret_cast<uint8_t *>((to_address)(first));
const auto __last = reinterpret_cast<uint8_t *>((to_address)(last));
const auto __first = reinterpret_cast<uint8_t *>(wjr::to_address(first));
const auto __last = reinterpret_cast<uint8_t *>(wjr::to_address(last));
const auto __result = __fast_to_chars_impl(__first, __last, val, ibase, conv);
return {first + std::distance(__first, __result.ptr), __result.ec};
} else {
Expand Down Expand Up @@ -1346,7 +1347,7 @@ Iter __fallback_to_chars_unchecked_impl(Iter ptr, Value val, IBase ibase,
} else { \
append(cont, n + sign, dctor); \
} \
const auto __end = (to_address)(cont.data() + cont.size()); \
const auto __end = wjr::to_address(cont.data() + cont.size()); \
auto __ptr = (convert_details::fast_buffer_t<Iter> *) \
__unsigned_to_chars_backward_unchecked<BASE>( \
(uint8_t *)__end, WJR_PP_QUEUE_EXPAND(CALL), conv); \
Expand Down Expand Up @@ -1409,7 +1410,7 @@ template <typename Iter, typename Value, typename IBase, typename Converter>
Iter __to_chars_unchecked_impl(Iter ptr, Value val, IBase ibase,
Converter conv) noexcept {
if constexpr (convert_details::__is_fast_convert_iterator_v<Iter>) {
const auto __ptr = reinterpret_cast<uint8_t *>((to_address)(ptr));
const auto __ptr = reinterpret_cast<uint8_t *>(wjr::to_address(ptr));
const auto __result = __fast_to_chars_unchecked_impl(__ptr, val, ibase, conv);
return ptr + std::distance(__ptr, __result);
} else {
Expand Down Expand Up @@ -1987,13 +1988,13 @@ Iter __fallback_biginteger_large_to_chars_impl(Iter ptr, const uint64_t *up, siz
} else { \
append(cont, SIZE, dctor); \
} \
const auto __ptr = (uint8_t *)(to_address)(cont.data()) + __presize; \
const auto __ptr = (uint8_t *)wjr::to_address(cont.data()) + __presize; \
const auto __size = NAME(__ptr, WJR_PP_QUEUE_EXPAND(CALL), conv) TAIL; \
WJR_ASSERT((size_t)__size <= SIZE); \
if constexpr (__fast_container_inserter_v == 1) { \
resize(cont, __presize + __size); \
} else { \
resize(cont, __presize + __size, wjr::dctor); \
resize(cont, __presize + __size, dctor); \
} \
\
return ptr; \
Expand Down Expand Up @@ -2048,7 +2049,7 @@ Iter __biginteger_to_chars_impl(Iter first, const uint64_t *up, size_t n,
}

if constexpr (convert_details::__is_fast_convert_iterator_v<Iter>) {
const auto __first = reinterpret_cast<uint8_t *>((to_address)(first));
const auto __first = reinterpret_cast<uint8_t *>(wjr::to_address(first));
const auto __result =
__fast_biginteger_large_to_chars_impl(__first, up, n, base, conv);
return first + std::distance(__first, __result);
Expand Down Expand Up @@ -2441,8 +2442,8 @@ template <typename Iter, typename Value, typename IBase, typename Converter,
WJR_REQUIRES(is_nonbool_integral_v<Value>)>
void __from_chars_unchecked_impl(Iter first, Iter last, Value &val, IBase ibase,
Converter conv) noexcept {
const auto __first = reinterpret_cast<const uint8_t *>((to_address)(first));
const auto __last = reinterpret_cast<const uint8_t *>((to_address)(last));
const auto __first = reinterpret_cast<const uint8_t *>(wjr::to_address(first));
const auto __last = reinterpret_cast<const uint8_t *>(wjr::to_address(last));
__fast_from_chars_unchecked_impl(__first, __last, val, ibase, conv);
}

Expand Down Expand Up @@ -3075,8 +3076,8 @@ uint64_t *biginteger_from_chars(Iter first, Iter last, uint64_t *up,
unsigned int base = 10, Converter conv = {}) noexcept {
WJR_ASSERT(base <= 36 && (is_zero_or_single_bit(base) || base == 10));

const auto __first = reinterpret_cast<const uint8_t *>((to_address)(first));
const auto __last = reinterpret_cast<const uint8_t *>((to_address)(last));
const auto __first = reinterpret_cast<const uint8_t *>(wjr::to_address(first));
const auto __last = reinterpret_cast<const uint8_t *>(wjr::to_address(last));

return __biginteger_from_chars_impl(__first, __last, up, base, conv);
}
Expand Down
4 changes: 2 additions & 2 deletions include/wjr/memory/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ constexpr OutputIt copy_restrict(InputIt first, InputIt last, OutputIt d_first)
const auto __first = try_to_address(std::move(first));
const auto __last = try_to_address(std::move(last));
if constexpr (is_contiguous_iterator_v<OutputIt>) {
const auto __d_first = (to_address)(d_first);
const auto __d_first = wjr::to_address(d_first);
const auto __d_last = __copy_restrict_impl(__first, __last, __d_first);
return std::next(d_first, std::distance(__d_first, __d_last));
} else {
Expand Down Expand Up @@ -146,7 +146,7 @@ template <typename InputIt, typename Size, typename OutputIt>
constexpr OutputIt copy_n_restrict(InputIt first, Size count, OutputIt d_first) {
const auto __first = try_to_address(std::move(first));
if constexpr (is_contiguous_iterator_v<OutputIt>) {
const auto __d_first = (to_address)(d_first);
const auto __d_first = wjr::to_address(d_first);
const auto __d_last = __copy_n_restrict_impl(__first, count, __d_first);
return std::next(d_first, std::distance(__d_first, __d_last));
} else {
Expand Down
6 changes: 3 additions & 3 deletions include/wjr/memory/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ constexpr auto to_address(const Ptr &p) noexcept {
if constexpr (has_pointer_traits_to_address_v<remove_cvref_t<Ptr>>) {
return std::pointer_traits<remove_cvref_t<Ptr>>::to_address(p);
} else {
return (to_address)(p.operator->());
return wjr::to_address(p.operator->());
}
}

Expand All @@ -43,7 +43,7 @@ constexpr auto to_address(const Ptr &p) noexcept {
*/
template <typename Iter, WJR_REQUIRES(is_contiguous_iterator_v<std::move_iterator<Iter>>)>
constexpr auto to_address(const std::move_iterator<Iter> &p) noexcept {
return (to_address)(p.base());
return wjr::to_address(p.base());
}

/**
Expand All @@ -55,7 +55,7 @@ template <typename T>
constexpr decltype(auto) try_to_address(T &&t) noexcept {
#if !WJR_HAS_DEBUG(CONTIGUOUS_ITERATOR_CHECK)
if constexpr (is_contiguous_iterator_v<remove_cvref_t<T>>) {
return (to_address)(std::forward<T>(t));
return wjr::to_address(std::forward<T>(t));
} else {
#endif
return std::forward<T>(t);
Expand Down
Loading

0 comments on commit c133507

Please sign in to comment.