Skip to content

Commit

Permalink
Adjust names to prevent collisions, fix assign.
Browse files Browse the repository at this point in the history
- Assignment had a few bugs in the base copy case (moves are still fine).
- Some derps in returning the value vs. capacity of the storage.
- Optional parameter for the assignment (maybe use optional instead of pointer for ease-of-API soon?)
  • Loading branch information
ThePhD committed Aug 24, 2020
1 parent 4c3b876 commit 761f0bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
21 changes: 13 additions & 8 deletions include/itsy/detail/small_bit_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,11 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
// so we have to literally transfer contents
// one by one by one...
// maybe we can move the contents?? Hopefully.
size_type __desired_count = __right.size();
this->_M_base_assign(
::std::make_move_iterator(__right._M_storage_pointer()),
::std::make_move_iterator(__right._M_storage_pointer_end()));
::std::make_move_iterator(__right._M_storage_pointer_end()),
&__desired_count);
}
}
}
Expand Down Expand Up @@ -392,7 +394,8 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
this->get_allocator() = __right.get_allocator();
}
// alright, now vomit out all the elements
this->_M_base_assign(__right._M_storage_pointer(), __right._M_storage_pointer_end());
size_type __desired_count = __right.size();
this->_M_base_assign(__right._M_storage_pointer(), __right._M_storage_pointer_end(), &__desired_count);
return *this;
}

Expand Down Expand Up @@ -1692,7 +1695,7 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
{
if (_S_is_sbo(__storage))
{
_S_storage_size_sbo(__storage);
return _S_storage_capacity_sbo(__storage);
}
return _S_storage_capacity_heap(__storage);
}
Expand All @@ -1714,7 +1717,7 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
{
if (_S_is_sbo(__storage))
{
_S_capacity_size_sbo(__storage);
return _S_capacity_sbo(__storage);
}
return _S_capacity_heap(__storage);
}
Expand Down Expand Up @@ -1881,7 +1884,7 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE

template<typename _It, typename _Sen>
void
_M_base_assign(_It __first, _Sen __last)
_M_base_assign(_It __first, _Sen __last, size_type* __maybe_desired_count = nullptr)
{
using _ItCategory = typename ::std::iterator_traits<_It>::iterator_category;

Expand All @@ -1896,7 +1899,7 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
if constexpr (__is_iterator_category_or_better_v<::std::random_access_iterator_tag, _ItCategory>)
{
size_type __desired_storage_count = static_cast<size_type>(__last - __first);
size_type __desired_count = __element_to_bit_size<__base_value_type>(__desired_storage_count);
size_type __desired_count = __maybe_desired_count ? *__maybe_desired_count : __element_to_bit_size<__base_value_type>(__desired_storage_count);
size_type __storage_capacity = this->_M_storage_capacity();
__base_pointer __storage_pointer = this->_M_storage_pointer();
bool __orphans_in_the_allocators_wake = __desired_storage_count > __storage_capacity;
Expand All @@ -1910,7 +1913,8 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
{
constexpr _S_construct_iterator_type<_It> __construction_fx = &_S_construct_iterator<_It>;
this->_S_trampoline_construct_n_using<false>(__mem_alloc, __storage_pointer,
__desired_storage_count, 0, __construction_fx, __first);
__desired_storage_count, __desired_storage_count,
__construction_fx, __first);
_S_set_size(this->_M_buf_or_ptr, __desired_count);
}
else
Expand Down Expand Up @@ -1962,7 +1966,8 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
++__first;
++__current_storage_size;
}
this->_M_set_size(__element_to_bit_size<__base_value_type>(__current_storage_size));
size_type __desired_count = __maybe_desired_count ? *__maybe_desired_count : __element_to_bit_size<__base_value_type>(__current_storage_size);
this->_M_set_size(__desired_count);
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/run_time/source/dynamic_bitset.assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <list>
#include <string>

TEMPLATE_TEST_CASE("bit_sequence assign test, signed", "[bit_sequence][assign][signed]", std::int64_t,
TEMPLATE_TEST_CASE("dynamic_bitset assign test, signed", "[dynamic_bitset][assign][signed]", std::int64_t,
std::int32_t, std::int16_t, std::int8_t, char, signed char, std::ptrdiff_t)
{
SECTION("normal")
Expand All @@ -27,8 +27,8 @@ TEMPLATE_TEST_CASE("bit_sequence assign test, signed", "[bit_sequence][assign][s
bitsy::dynamic_bitset<TestType> destination0;
bitsy::dynamic_bitset<TestType> destination1;
destination0 = source0;
destination1 = source1;
REQUIRE(destination0 == source0);
destination1 = source1;
REQUIRE(destination1 == source1);
}
SECTION("packed")
Expand All @@ -38,13 +38,13 @@ TEMPLATE_TEST_CASE("bit_sequence assign test, signed", "[bit_sequence][assign][s
bitsy::packed_dynamic_bitset<TestType> destination0;
bitsy::packed_dynamic_bitset<TestType> destination1;
destination0 = source0;
destination1 = source1;
REQUIRE(destination0 == source0);
destination1 = source1;
REQUIRE(destination1 == source1);
}
}

TEMPLATE_TEST_CASE("bit_sequence assign test, signed", "[bit_sequence][assign][unsigned]", std::uint64_t,
TEMPLATE_TEST_CASE("dynamic_bitset assign test, signed", "[dynamic_bitset][assign][unsigned]", std::uint64_t,
std::uint32_t, std::uint16_t, std::uint8_t, std::byte, char32_t, char16_t, unsigned char, std::size_t)
{
SECTION("normal")
Expand All @@ -54,8 +54,8 @@ TEMPLATE_TEST_CASE("bit_sequence assign test, signed", "[bit_sequence][assign][u
bitsy::dynamic_bitset<TestType> destination0;
bitsy::dynamic_bitset<TestType> destination1;
destination0 = source0;
destination1 = source1;
REQUIRE(destination0 == source0);
destination1 = source1;
REQUIRE(destination1 == source1);
}
SECTION("packed")
Expand All @@ -65,8 +65,8 @@ TEMPLATE_TEST_CASE("bit_sequence assign test, signed", "[bit_sequence][assign][u
bitsy::packed_dynamic_bitset<TestType> destination0;
bitsy::packed_dynamic_bitset<TestType> destination1;
destination0 = source0;
destination1 = source1;
REQUIRE(destination0 == source0);
destination1 = source1;
REQUIRE(destination1 == source1);
}
}

0 comments on commit 761f0bd

Please sign in to comment.