Skip to content

Commit

Permalink
conditional around vector<bool>
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Sep 5, 2024
1 parent 5851198 commit a164856
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/include/duckdb/common/stl_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,29 @@ bool operator==(const stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return true;
}

template <class T, class U>
bool operator==(stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return true;
}

template <class T, class U>
bool operator==(const stl_allocator<T> &, stl_allocator<U> &) noexcept {
return true;
}

template <class T, class U>
bool operator!=(const stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return false;
}

template <class T, class U>
bool operator!=(stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return false;
}

template <class T, class U>
bool operator!=(const stl_allocator<T> &, stl_allocator<U> &) noexcept {
return false;
}

} // namespace duckdb
8 changes: 5 additions & 3 deletions src/include/duckdb/common/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ void ThrowEraseAtException(duckdb::idx_t index, duckdb::idx_t size);

namespace duckdb {

template <class DATA_TYPE, bool SAFE = true>
class vector : public std::vector<DATA_TYPE, stl_allocator<DATA_TYPE>> { // NOLINT: matching name of std
template <class DATA_TYPE, bool SAFE = true, // vector<bool> is evil so we work around it
class ALLOCATOR = typename std::conditional<std::is_same<DATA_TYPE, bool>::value, std::allocator<DATA_TYPE>,
stl_allocator<DATA_TYPE>>::type>
class vector : public std::vector<DATA_TYPE, ALLOCATOR> { // NOLINT: matching name of std
public:
using original = std::vector<DATA_TYPE, stl_allocator<DATA_TYPE>>;
using original = std::vector<DATA_TYPE, ALLOCATOR>;
using original::original;
using size_type = typename original::size_type;
using const_reference = typename original::const_reference;
Expand Down

0 comments on commit a164856

Please sign in to comment.