mirror of
https://github.com/BlackMATov/flat.hpp.git
synced 2025-12-16 22:16:58 +07:00
fix msvc compilation
This commit is contained in:
@@ -17,16 +17,32 @@ namespace
|
|||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
T* allocate(std::size_t n) {
|
dummy_allocator() = default;
|
||||||
|
|
||||||
|
template < typename U >
|
||||||
|
dummy_allocator(const dummy_allocator<U>&) noexcept {
|
||||||
|
}
|
||||||
|
|
||||||
|
T* allocate(std::size_t n) noexcept {
|
||||||
return static_cast<T*>(std::malloc(sizeof(T) * n));
|
return static_cast<T*>(std::malloc(sizeof(T) * n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate(T* p, std::size_t n) {
|
void deallocate(T* p, std::size_t n) noexcept {
|
||||||
(void)n;
|
(void)n;
|
||||||
std::free(p);
|
std::free(p);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template < typename T, typename U >
|
||||||
|
bool operator==(const dummy_allocator<T>&, const dummy_allocator<U>&) noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename T, typename U >
|
||||||
|
bool operator!=(const dummy_allocator<T>& l, const dummy_allocator<U>& r) noexcept {
|
||||||
|
return !(l == r);
|
||||||
|
}
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
constexpr std::add_const_t<T>& my_as_const(T& t) noexcept {
|
constexpr std::add_const_t<T>& my_as_const(T& t) noexcept {
|
||||||
return t;
|
return t;
|
||||||
@@ -150,6 +166,7 @@ TEST_CASE("flat_map") {
|
|||||||
REQUIRE(s0.at(1) == 84);
|
REQUIRE(s0.at(1) == 84);
|
||||||
REQUIRE(my_as_const(s0).at(1) == 84);
|
REQUIRE(my_as_const(s0).at(1) == 84);
|
||||||
REQUIRE_THROWS_AS(s0.at(0), std::out_of_range);
|
REQUIRE_THROWS_AS(s0.at(0), std::out_of_range);
|
||||||
|
REQUIRE_THROWS_AS(my_as_const(s0).at(0), std::out_of_range);
|
||||||
}
|
}
|
||||||
SECTION("inserts") {
|
SECTION("inserts") {
|
||||||
struct obj_t {
|
struct obj_t {
|
||||||
@@ -186,13 +203,16 @@ TEST_CASE("flat_map") {
|
|||||||
REQUIRE(i3 == s0.begin() + 2);
|
REQUIRE(i3 == s0.begin() + 2);
|
||||||
|
|
||||||
s0.insert(s0.cend(), std::make_pair(4, obj_t(84)));
|
s0.insert(s0.cend(), std::make_pair(4, obj_t(84)));
|
||||||
|
auto i4 = s0.insert(s0.cend(), std::make_pair(0, obj_t(21)));
|
||||||
|
REQUIRE(i4 == s0.begin());
|
||||||
|
|
||||||
auto i4 = s0.emplace(5, 100500);
|
auto i5 = s0.emplace(5, 100500);
|
||||||
REQUIRE(i4 == std::make_pair(s0.end() - 1, true));
|
REQUIRE(i5 == std::make_pair(s0.end() - 1, true));
|
||||||
REQUIRE(s0 == map_t{{1,42},{2,42},{3,84},{4,84},{5,100500}});
|
REQUIRE(s0 == map_t{{0,21},{1,42},{2,42},{3,84},{4,84},{5,100500}});
|
||||||
|
|
||||||
auto i5 = s0.emplace_hint(s0.cend(), 6, 100500);
|
auto i6 = s0.emplace_hint(s0.cend(), 6, 100500);
|
||||||
REQUIRE(s0 == map_t{{1,42},{2,42},{3,84},{4,84},{5,100500},{6,100500}});
|
REQUIRE(i6 == s0.end() - 1);
|
||||||
|
REQUIRE(s0 == map_t{{0,21},{1,42},{2,42},{3,84},{4,84},{5,100500},{6,100500}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SECTION("erasers") {
|
SECTION("erasers") {
|
||||||
|
|||||||
@@ -17,16 +17,32 @@ namespace
|
|||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
|
|
||||||
T* allocate(std::size_t n) {
|
dummy_allocator() = default;
|
||||||
|
|
||||||
|
template < typename U >
|
||||||
|
dummy_allocator(const dummy_allocator<U>&) noexcept {
|
||||||
|
}
|
||||||
|
|
||||||
|
T* allocate(std::size_t n) noexcept {
|
||||||
return static_cast<T*>(std::malloc(sizeof(T) * n));
|
return static_cast<T*>(std::malloc(sizeof(T) * n));
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate(T* p, std::size_t n) {
|
void deallocate(T* p, std::size_t n) noexcept {
|
||||||
(void)n;
|
(void)n;
|
||||||
std::free(p);
|
std::free(p);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template < typename T, typename U >
|
||||||
|
bool operator==(const dummy_allocator<T>&, const dummy_allocator<U>&) noexcept {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename T, typename U >
|
||||||
|
bool operator!=(const dummy_allocator<T>& l, const dummy_allocator<U>& r) noexcept {
|
||||||
|
return !(l == r);
|
||||||
|
}
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
constexpr std::add_const_t<T>& my_as_const(T& t) noexcept {
|
constexpr std::add_const_t<T>& my_as_const(T& t) noexcept {
|
||||||
return t;
|
return t;
|
||||||
@@ -159,6 +175,10 @@ TEST_CASE("flat_set") {
|
|||||||
REQUIRE(s0 == set_t{1,2});
|
REQUIRE(s0 == set_t{1,2});
|
||||||
REQUIRE(i2 == std::make_pair(s0.begin() + 1, true));
|
REQUIRE(i2 == std::make_pair(s0.begin() + 1, true));
|
||||||
|
|
||||||
|
auto o2 = obj_t(2);
|
||||||
|
auto i3 = s0.insert(o2);
|
||||||
|
REQUIRE(i3 == std::make_pair(s0.begin() + 1, false));
|
||||||
|
|
||||||
s0.insert(s0.cbegin(), 1);
|
s0.insert(s0.cbegin(), 1);
|
||||||
s0.insert(s0.cbegin(), 2);
|
s0.insert(s0.cbegin(), 2);
|
||||||
s0.insert(s0.cend(), 1);
|
s0.insert(s0.cend(), 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user