Skip to content

Commit

Permalink
update json
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Aug 13, 2024
1 parent 87c0a81 commit 75990fd
Show file tree
Hide file tree
Showing 9 changed files with 16,451 additions and 295 deletions.
2 changes: 1 addition & 1 deletion include/wjr/compressed_pair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class WJR_EMPTY_BASES compressed_pair final : __compressed_pair_base1<T, U>,
template <typename Myself = compressed_pair, typename _T = T,
WJR_REQUIRES(std::conjunction_v<is_swappable<_T>, is_swappable<U>>)>
constexpr void swap(type_identity_t<compressed_pair &> other) noexcept(
std::conjunction_v<is_nothrow_swappable<T>, is_nothrow_swappable<U>>) {
std::conjunction_v<std::is_nothrow_swappable<T>, std::is_nothrow_swappable<U>>) {
std::swap(first(), other.first());
std::swap(second(), other.second());
}
Expand Down
16 changes: 8 additions & 8 deletions include/wjr/json/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ template <typename T>
using result = expected<T, result_error>;

enum class value_t : uint8_t {
null,
boolean,
number_unsigned,
number_signed,
number_float,
string,
object,
array,
null = 0,
boolean = 1,
number_unsigned = 2,
number_signed = 3,
number_float = 4,
string = 5,
object = 6,
array = 7,
};

/// @brief used for identify null type (std::nullptr_t)
Expand Down
1,016 changes: 808 additions & 208 deletions include/wjr/json/json.hpp

Large diffs are not rendered by default.

22 changes: 0 additions & 22 deletions include/wjr/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,28 +279,6 @@ struct is_swappable
template <typename T>
inline constexpr bool is_swappable_v = is_swappable<T>::value;

template <typename T, typename U>
struct __is_nothrow_swappable_with
: std::bool_constant<noexcept(std::swap(std::declval<T &>(), std::declval<U &>())) &&
noexcept(std::swap(std::declval<U &>(), std::declval<T &>()))> {
};

template <typename T, typename U>
struct is_nothrow_swappable_with
: std::conjunction<is_swappable_with<T, U>, __is_nothrow_swappable_with<T, U>> {};

template <typename T, typename U>
inline constexpr bool is_nothrow_swappable_with_v =
is_nothrow_swappable_with<T, U>::value;

template <typename T>
struct is_nothrow_swappable : is_nothrow_swappable_with<std::add_lvalue_reference_t<T>,
std::add_lvalue_reference_t<T>> {
};

template <typename T>
inline constexpr bool is_nothrow_swappable_v = is_nothrow_swappable<T>::value;

/// @private
template <typename T>
struct __unref_wrapper_helper {
Expand Down
34 changes: 6 additions & 28 deletions tests/units/src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const static std::string __string2 = std::string("abc");

using namespace wjr;

static_assert(sizeof(sso_vector<char, 16>) <= 32, "");

static_assert(is_contiguous_iterator_v<typename vector<int>::iterator>, "");
static_assert(is_contiguous_iterator_v<typename vector<int>::const_iterator>, "");

static_assert(is_contiguous_iterator_v<typename vector<std::string>::iterator>, "");
static_assert(is_contiguous_iterator_v<typename vector<std::string>::const_iterator>, "");

static_assert(is_trivially_allocator_v<memory_pool<int>>, "");

template <typename Iter, typename Func>
void for_each_n(Iter first, size_t n, Func fn) {
for (size_t i = 0; i < n; ++i) {
Expand Down Expand Up @@ -734,8 +734,8 @@ TEST(vector, swap) {

for (int n = 0; n < 16; ++n)
for (int m = 0; m < 16; ++m) {
static_vector<int, 16> v1(n, 1);
static_vector<int, 16> v2(m, 2);
inplace_vector<int, 16> v1(n, 1);
inplace_vector<int, 16> v2(m, 2);
v1.swap(v2);
EXPECT_EQ(v1.size(), m);
EXPECT_EQ(v2.size(), n);
Expand All @@ -745,30 +745,8 @@ TEST(vector, swap) {

for (int n = 0; n < 32; ++n)
for (int m = 0; m < 32; ++m) {
static_vector<int, 32> v1(n, 1);
static_vector<int, 32> v2(m, 2);
v1.swap(v2);
EXPECT_EQ(v1.size(), m);
EXPECT_EQ(v2.size(), n);
for_each_n(v1.begin(), m, [](auto &x) { EXPECT_EQ(x, 2); });
for_each_n(v2.begin(), n, [](auto &x) { EXPECT_EQ(x, 1); });
}

for (int n = 0; n < 32; ++n)
for (int m = 0; m < 32; ++m) {
sso_vector<int, 16> v1(n, 1);
sso_vector<int, 16> v2(m, 2);
v1.swap(v2);
EXPECT_EQ(v1.size(), m);
EXPECT_EQ(v2.size(), n);
for_each_n(v1.begin(), m, [&](auto &x) { EXPECT_EQ(x, 2); });
for_each_n(v2.begin(), n, [](auto &x) { EXPECT_EQ(x, 1); });
}

for (int n = 0; n < 48; ++n)
for (int m = 0; m < 48; ++m) {
sso_vector<int, 32> v1(n, 1);
sso_vector<int, 32> v2(m, 2);
inplace_vector<int, 32> v1(n, 1);
inplace_vector<int, 32> v2(m, 2);
v1.swap(v2);
EXPECT_EQ(v1.size(), m);
EXPECT_EQ(v2.size(), n);
Expand Down
Loading

0 comments on commit 75990fd

Please sign in to comment.