Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Sep 23, 2024
1 parent eafe671 commit 4d56ee6
Show file tree
Hide file tree
Showing 28 changed files with 212 additions and 173 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif()

option(WJR_ENABLE_ASSEMBLY "Link with assembly by using NASM" OFF)
option(WJR_ENABLE_INLINE_ASM "Enable inline assembly in GCC/Clang" ON)
option(WJR_DISABLE_EXCEPTIONS "Disable exceptions" OFF)
option(WJR_DISABLE_EXCEPTIONS "Disable exceptions" ON)

if (DEFINED WJR_DEBUG_LEVEL AND (NOT DEFINED WJR_DEBUG_LEVEL_DEBUG))
set(WJR_DEBUG_LEVEL_DEBUG ${WJR_DEBUG_LEVEL})
Expand Down
1 change: 0 additions & 1 deletion atomic
Submodule atomic deleted from fbdb5f
2 changes: 0 additions & 2 deletions include/wjr/arch/x86/math/mul-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include <wjr/type_traits.hpp>



namespace wjr {

#define WJR_HAS_BUILTIN_UMUL128 WJR_HAS_DEF
Expand Down
4 changes: 2 additions & 2 deletions include/wjr/capture_leaf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class capture_leaf : enable_special_members_of_args_base<Tag, T> {
: Mybase(enable_default_constructor), m_value(std::forward<Args>(args)...) {}

template <typename Ty = T, WJR_REQUIRES(std::is_default_constructible_v<Ty>)>
constexpr explicit capture_leaf(dctor_t) noexcept(
constexpr explicit capture_leaf(default_construct_t) noexcept(
std::is_nothrow_default_constructible_v<T>)
: Mybase(enable_default_constructor) {}

Expand Down Expand Up @@ -67,7 +67,7 @@ class compressed_capture_leaf : T {
: Mybase(std::forward<Args>(args)...) {}

template <typename Ty = T, WJR_REQUIRES(std::is_default_constructible_v<Ty>)>
constexpr explicit compressed_capture_leaf(dctor_t) noexcept(
constexpr explicit compressed_capture_leaf(default_construct_t) noexcept(
std::is_nothrow_default_constructible_v<T>) {}

constexpr T &get() noexcept { return *this; }
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/container/generic/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class bitset {

public:
constexpr bitset() noexcept : m_data() {}
constexpr explicit bitset(dctor_t) noexcept {}
constexpr explicit bitset(default_construct_t) noexcept {}

bitset(const bitset &) = default;
bitset(bitset &&) = default;
Expand Down
3 changes: 2 additions & 1 deletion include/wjr/container/generic/bmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace wjr {
template <typename Key, typename Value, typename Pr, bool TrivialSearch>
using __bmap_traits = btree_traits<Key, Value, false, Pr, TrivialSearch>;

template <typename Key, typename Value, typename Pr = std::less<Key>, bool TrivialSearch = true>
template <typename Key, typename Value, typename Pr = std::less<Key>,
bool TrivialSearch = true>
class bmap : public basic_btree<__bmap_traits<Key, Value, Pr, TrivialSearch>> {
using Traits = __bmap_traits<Key, Value, Pr, TrivialSearch>;
using Mybase = basic_btree<Traits>;
Expand Down
4 changes: 2 additions & 2 deletions include/wjr/container/generic/btree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,15 @@ class basic_btree {
_Alty al;
auto *const node = reinterpret_cast<inner_node_type *>(
_Alty_traits::allocate(al, sizeof(inner_node_type)));
uninitialized_construct_using_allocator(node, al, dctor);
uninitialized_construct_using_allocator(node, al, default_construct);
return node;
}

WJR_INTRINSIC_INLINE static leaf_node_type *__create_leaf_node() noexcept {
_Alty al;
auto *const node = reinterpret_cast<leaf_node_type *>(
_Alty_traits::allocate(al, sizeof(leaf_node_type)));
uninitialized_construct_using_allocator(node, al, dctor);
uninitialized_construct_using_allocator(node, al, default_construct);
return node;
}

Expand Down
5 changes: 5 additions & 0 deletions include/wjr/container/generic/container_fn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

namespace wjr {

template <typename T, typename D>
struct get_relocate_mode<std::unique_ptr<T, D>> {
static constexpr relocate_t value = relocate_t::maybe_trivial;
};

/**
* @class container_fn<Alloc>
* @brief The same characteristics and behavior of all allocator containers
Expand Down
8 changes: 4 additions & 4 deletions include/wjr/container/generic/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ WJR_REGISTER_HAS_TYPE(container_insert,
template <typename Container, typename Size,
WJR_REQUIRES(has_container_resize_v<Container, Size>)>
WJR_INTRINSIC_INLINE void try_uninitialized_resize(Container &cont, Size sz) {
if constexpr (has_container_resize_v<Container, Size, dctor_t>) {
resize(cont, sz, dctor);
if constexpr (has_container_resize_v<Container, Size, default_construct_t>) {
resize(cont, sz, default_construct);
} else {
resize(cont, sz);
}
Expand All @@ -97,8 +97,8 @@ template <typename Container, typename Size,
WJR_REQUIRES(has_container_append_v<Container, Size> ||
has_container_resize_v<Container, Size>)>
WJR_INTRINSIC_INLINE void try_uninitialized_append(Container &cont, Size sz) {
if constexpr (has_container_append_v<Container, Size, dctor_t>) {
append(cont, sz, dctor);
if constexpr (has_container_append_v<Container, Size, default_construct_t>) {
append(cont, sz, default_construct);
} else {
try_uninitialized_resize(cont, cont.size() + sz);
}
Expand Down
26 changes: 15 additions & 11 deletions include/wjr/container/generic/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class basic_vector {
const allocator_type &al = allocator_type())
: m_pair(std::piecewise_construct, wjr::forward_as_tuple(al),
wjr::forward_as_tuple()) {
__construct_n(n, vctor);
__construct_n(n, value_construct);
}

WJR_CONSTEXPR20 basic_vector(size_type n, const value_type &val,
Expand Down Expand Up @@ -667,7 +667,9 @@ class basic_vector {
return get_storage().size();
}

WJR_CONSTEXPR20 void resize(const size_type new_size) { __resize(new_size, vctor); }
WJR_CONSTEXPR20 void resize(const size_type new_size) {
__resize(new_size, value_construct);
}

WJR_CONSTEXPR20 void resize(const size_type new_size, const value_type &val) {
__resize(new_size, val);
Expand Down Expand Up @@ -919,11 +921,11 @@ class basic_vector {

// extension

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

WJR_CONSTEXPR20 basic_vector(size_type n, in_place_reserve_t,
Expand Down Expand Up @@ -980,11 +982,13 @@ class basic_vector {
*/
WJR_CONSTEXPR20 void clear_if_reserved(size_type n) { __clear_if_reserved_impl(n); }

WJR_CONSTEXPR20 void resize(const size_type new_size, dctor_t) {
__resize(new_size, dctor);
WJR_CONSTEXPR20 void resize(const size_type new_size, default_construct_t) {
__resize(new_size, default_construct);
}

WJR_CONSTEXPR20 void push_back(dctor_t) { emplace_back(dctor); }
WJR_CONSTEXPR20 void push_back(default_construct_t) {
emplace_back(default_construct);
}

WJR_CONSTEXPR20 basic_vector &append(const value_type &val) {
emplace_back(val);
Expand All @@ -996,8 +1000,8 @@ class basic_vector {
return *this;
}

WJR_CONSTEXPR20 basic_vector &append(dctor_t) {
emplace_back(dctor);
WJR_CONSTEXPR20 basic_vector &append(default_construct_t) {
emplace_back(default_construct);
return *this;
}

Expand All @@ -1006,8 +1010,8 @@ class basic_vector {
return *this;
}

WJR_CONSTEXPR20 basic_vector &append(const size_type n, dctor_t) {
__append(n, dctor);
WJR_CONSTEXPR20 basic_vector &append(const size_type n, default_construct_t) {
__append(n, default_construct);
return *this;
}

Expand Down
6 changes: 6 additions & 0 deletions include/wjr/container/intrusive/forward_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ constexpr void push_front(forward_list_node_base *head,
insert_after(head, node);
}

constexpr void push_back(forward_list_node_base *tail,
forward_list_node_base *node) noexcept {
WJR_ASSERT_ASSUME(tail->m_next == nullptr);
tail->m_next = node;
}

constexpr bool empty(const forward_list_node_base *node) noexcept {
return node->m_next == nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/container/intrusive/list.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef WJR_CONTAINER_INTRUSIVE_LIST_HPP__
#define WJR_CONTAINER_INTRUSIVE_LIST_HPP__

#include <wjr/type_traits.hpp>
#include <wjr/assert.hpp>
#include <wjr/type_traits.hpp>

namespace wjr::intrusive {

Expand Down
8 changes: 5 additions & 3 deletions include/wjr/format/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ struct __fast_container_inserter_test {
static constexpr int value =
traits_type::is_trivially_contiguous_v &&
has_container_resize_v<Container, size_t>
? (has_container_resize_v<Container, size_t, dctor_t> ? 2 : 1)
? (has_container_resize_v<Container, size_t, default_construct_t> ? 2 : 1)
: 0;

static_assert(value != 2 || has_container_append_v<Container, size_t, dctor_t>, "");
static_assert(value != 2 ||
has_container_append_v<Container, size_t, default_construct_t>,
"");
};

template <typename Iter, typename = void>
Expand Down Expand Up @@ -1296,7 +1298,7 @@ Iter __fallback_to_chars_unchecked_impl(Iter ptr, Value val, IBase ibase,
if constexpr (__fast_container_inserter_v == 1) { \
resize(cont, cont.size() + n + sign); \
} else { \
append(cont, n + sign, dctor); \
append(cont, n + sign, default_construct); \
} \
auto *const __end = cont.data() + cont.size(); \
auto __ptr = (charconv_detail::fast_buffer_t<Iter> *) \
Expand Down
3 changes: 2 additions & 1 deletion include/wjr/format/fastfloat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,8 @@ adjusted_mantissa negative_digit_comp(fixed_biginteger &bigmant, adjusted_mantis
fixed_biginteger &real_digits = bigmant;
int32_t real_exp = exponent;

// get the value of `b`, rounded down, and get a fixed_biginteger representation of b+h
// get the value of `b`, rounded down, and get a fixed_biginteger representation of
// b+h
adjusted_mantissa am_b = am;
// gcc7 buf: use a lambda to remove the noexcept qualifier bug with
// -Wnoexcept-type.
Expand Down
71 changes: 37 additions & 34 deletions include/wjr/json/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,37 +316,49 @@ WJR_REGISTER_HAS_TYPE(construct_to_json,
// to_json

#define __WJR_REGISTER_TO_JSON_SERIALIZER_COPY_CONSTRUCTOR_CALLER(var) \
({#var, Json(__wjr_tp.var)})
__wjr_obj.emplace(#var, __wjr_tp.var)
#define __WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_CONSTRUCTOR_CALLER(var) \
({#var, Json(std::move(__wjr_tp.var))})
__wjr_obj.emplace(#var, std::move(__wjr_tp.var))

#define WJR_REGISTER_TO_JSON_SERIALIZER_COPY_BASE(Type, ...) \
template <typename Json> \
static void assign_object(const Type &__wjr_tp, Json &__wjr_json, \
::wjr::json::in_place_json_serializer_t) { \
using namespace wjr::json; \
auto &__wjr_obj = __wjr_json.template get_unsafe<object_t>(); \
WJR_PP_QUEUE_EXPAND(WJR_PP_QUEUE_TRANSFORM( \
(__VA_ARGS__), __WJR_REGISTER_TO_JSON_SERIALIZER_COPY_CONSTRUCTOR_CALLER)); \
}

#define WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_BASE(Type, ...) \
template <typename Json> \
static void assign_object(Type &&__wjr_tp, Json &__wjr_json, \
::wjr::json::in_place_json_serializer_t) { \
using namespace wjr::json; \
auto &__wjr_obj = __wjr_json.template get_unsafe<object_t>(); \
WJR_PP_QUEUE_EXPAND(WJR_PP_QUEUE_TRANSFORM( \
(__VA_ARGS__), __WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_CONSTRUCTOR_CALLER)); \
}

#define WJR_REGISTER_TO_JSON_SERIALIZER_COPY_CONSTRUCTOR(Type, ...) \
template <typename Json> \
static Json construct(const Type &__wjr_tp, \
::wjr::json::in_place_json_serializer_t) { \
using namespace wjr::json; \
using object_type = typename Json::object_type; \
using value_type = typename object_type::value_type; \
return Json( \
object_t(), \
__json_create<object_type>(std::initializer_list<value_type>{ \
WJR_PP_QUEUE_EXPAND(WJR_PP_QUEUE_UNWRAP(WJR_PP_QUEUE_TRANSFORM( \
(__VA_ARGS__), \
__WJR_REGISTER_TO_JSON_SERIALIZER_COPY_CONSTRUCTOR_CALLER)))})); \
Json __wjr_json(object_t(), __json_create<object_type>()); \
assign_object(__wjr_tp, __wjr_json, in_place_json_serializer); \
return __wjr_json; \
}

#define WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_CONSTRUCTOR(Type, ...) \
template <typename Json> \
static Json construct(Type &&__wjr_tp, ::wjr::json::in_place_json_serializer_t) { \
using namespace wjr::json; \
using object_type = typename Json::object_type; \
using value_type = typename object_type::value_type; \
return Json( \
object_t(), \
__json_create<object_type>(std::initializer_list<value_type>{ \
WJR_PP_QUEUE_EXPAND(WJR_PP_QUEUE_UNWRAP(WJR_PP_QUEUE_TRANSFORM( \
(__VA_ARGS__), \
__WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_CONSTRUCTOR_CALLER)))})); \
Json __wjr_json(object_t(), __json_create<object_type>()); \
assign_object(std::move(__wjr_tp), __wjr_json, in_place_json_serializer); \
return __wjr_json; \
}

#define WJR_REGISTER_TO_JSON_SERIALIZER_COPY_ASSIGNMENT(Type, ...) \
Expand All @@ -356,17 +368,11 @@ WJR_REGISTER_HAS_TYPE(construct_to_json,
using namespace wjr::json; \
using Json = basic_json<Traits>; \
using object_type = typename Json::object_type; \
using value_type = typename object_type::value_type; \
auto il = std::initializer_list<value_type>{ \
WJR_PP_QUEUE_EXPAND(WJR_PP_QUEUE_UNWRAP(WJR_PP_QUEUE_TRANSFORM( \
(__VA_ARGS__), \
__WJR_REGISTER_TO_JSON_SERIALIZER_COPY_CONSTRUCTOR_CALLER)))}; \
if (__wjr_json.type() != value_t::object) { \
__wjr_json.reset(); \
__wjr_json.set(object_t(), __json_create<object_type>(il)); \
} else { \
__wjr_json.template get_unsafe<object_t> = il; \
__wjr_json.set(object_t(), __json_create<object_type>()); \
} \
assign_object(__wjr_tp, __wjr_json, in_place_json_serializer); \
}

#define WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_ASSIGNMENT(Type, ...) \
Expand All @@ -375,20 +381,16 @@ WJR_REGISTER_HAS_TYPE(construct_to_json,
using namespace wjr::json; \
using Json = basic_json<Traits>; \
using object_type = typename Json::object_type; \
using value_type = typename object_type::value_type; \
auto il = std::initializer_list<value_type>{ \
WJR_PP_QUEUE_EXPAND(WJR_PP_QUEUE_UNWRAP(WJR_PP_QUEUE_TRANSFORM( \
(__VA_ARGS__), \
__WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_CONSTRUCTOR_CALLER)))}; \
if (__wjr_json.type() != value_t::object) { \
__wjr_json.reset(); \
__wjr_json.set(object_t(), __json_create<object_type>(il)); \
} else { \
__wjr_json.template get_unsafe<object_t> = il; \
__wjr_json.set(object_t(), __json_create<object_type>()); \
} \
assign_object(std::move(__wjr_tp), __wjr_json, in_place_json_serializer); \
}

#define WJR_REGISTER_TO_JSON_SERIALIZER_DEFAULT(Type, ...) \
WJR_REGISTER_TO_JSON_SERIALIZER_COPY_BASE(Type, __VA_ARGS__) \
WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_BASE(Type, __VA_ARGS__) \
WJR_REGISTER_TO_JSON_SERIALIZER_COPY_CONSTRUCTOR(Type, __VA_ARGS__) \
WJR_REGISTER_TO_JSON_SERIALIZER_MOVE_CONSTRUCTOR(Type, __VA_ARGS__) \
WJR_REGISTER_TO_JSON_SERIALIZER_COPY_ASSIGNMENT(Type, __VA_ARGS__) \
Expand Down Expand Up @@ -682,7 +684,7 @@ class basic_json {
basic_json(array_t, array_type *ptr) noexcept : m_value(array_t(), ptr) {}

explicit basic_json(basic_value value) noexcept : m_value(value) {}
explicit basic_json(dctor_t) noexcept : basic_json() {}
explicit basic_json(default_construct_t) noexcept : basic_json() {}

WJR_PURE value_t type() const noexcept { return m_value.m_type; }

Expand Down Expand Up @@ -1754,7 +1756,8 @@ class basic_json_parser {

WJR_EXPECTED_INIT(ret, parse_string(str.data(), first, last));
str.resize(*ret - str.data());
const auto iter = current->__get_object().try_emplace(std::move(str), dctor);
const auto iter =
current->__get_object().try_emplace(std::move(str), default_construct);
element = std::addressof(iter.first->second);
if (WJR_UNLIKELY(!iter.second)) {
element->reset();
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/json/visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ template <typename Parser>
WJR_NOINLINE result<void> parse(Parser &&par, const reader &rd) noexcept {
constexpr unsigned int max_depth = 256;

bitset<max_depth> stk(dctor);
bitset<max_depth> stk(default_construct);
unsigned int depth = 0;
uint8_t type;

Expand Down
2 changes: 1 addition & 1 deletion include/wjr/math/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ WJR_CONST WJR_INTRINSIC_CONSTEXPR20 T bit_ceil(T x) noexcept {
if (x <= 1) {
return T(1);
}

if constexpr (std::is_same_v<T, decltype(+x)>) {
return T(1) << bit_width(T(x - 1));
} else {
Expand Down
Loading

0 comments on commit 4d56ee6

Please sign in to comment.