mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-09 03:20:42 +02:00
FixedCapacityContainer fix for clang
This commit is contained in:
parent
d597636c1e
commit
1b06edac9b
@ -50,26 +50,26 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compare FixedCapacityContainer with any other container*/
|
/** Compare FixedCapacityContainer with any other container*/
|
||||||
template <typename V>
|
// template <typename V>
|
||||||
typename std::enable_if<is_container<V>::value, bool>::type
|
// typename std::enable_if<is_container<V>::value, bool>::type
|
||||||
operator==(const V &other) const noexcept {
|
// operator==(const V &other) const noexcept {
|
||||||
if (current_size != other.size()) {
|
// if (current_size != other.size()) {
|
||||||
return false;
|
// return false;
|
||||||
} else {
|
// } else {
|
||||||
for (size_t i = 0; i != current_size; ++i) {
|
// for (size_t i = 0; i != current_size; ++i) {
|
||||||
if (data_[i] != other[i]) {
|
// if (data_[i] != other[i]) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
template <typename V>
|
// template <typename V>
|
||||||
typename std::enable_if<is_container<V>::value, bool>::type
|
// typename std::enable_if<is_container<V>::value, bool>::type
|
||||||
operator!=(const V &other) const noexcept {
|
// operator!=(const V &other) const noexcept {
|
||||||
return !(*this == other);
|
// return !(*this == other);
|
||||||
}
|
// }
|
||||||
|
|
||||||
operator std::vector<T>() { return std::vector<T>(begin(), end()); }
|
operator std::vector<T>() { return std::vector<T>(begin(), end()); }
|
||||||
|
|
||||||
@ -103,6 +103,20 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
|
|||||||
throw std::runtime_error("tried to erase with a ptr outside obj");
|
throw std::runtime_error("tried to erase with a ptr outside obj");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Container> bool is_equal(const Container &c) const noexcept {
|
||||||
|
if (current_size != c.size()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
for (size_t i = 0; i != current_size; ++i) {
|
||||||
|
if (data_[i] != c[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
T &front() noexcept { return data_.front(); }
|
T &front() noexcept { return data_.front(); }
|
||||||
T &back() noexcept { return data_[current_size - 1]; }
|
T &back() noexcept { return data_[current_size - 1]; }
|
||||||
constexpr const T &front() const noexcept { return data_.front(); }
|
constexpr const T &front() const noexcept { return data_.front(); }
|
||||||
@ -127,20 +141,84 @@ template <typename T, size_t Capacity> class FixedCapacityContainer {
|
|||||||
|
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
/** support flipped order compare */
|
template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs>
|
||||||
template <typename T, size_t Capacity, typename C>
|
bool operator==(const FixedCapacityContainer<T, CapacityLhs> &lhs,
|
||||||
typename std::enable_if<is_container<C>::value, bool>::type operator==(
|
const FixedCapacityContainer<V, CapacityRhs> &rhs) {
|
||||||
const C &container,
|
return lhs.is_equal(rhs);
|
||||||
const FixedCapacityContainer<T, Capacity> &fixed_container) noexcept {
|
}
|
||||||
return fixed_container.operator==(container);
|
|
||||||
|
template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs>
|
||||||
|
bool operator!=(const FixedCapacityContainer<T, CapacityLhs> &lhs,
|
||||||
|
const FixedCapacityContainer<V, CapacityRhs> &rhs) {
|
||||||
|
return !(lhs.is_equal(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare with array
|
||||||
|
|
||||||
|
template <typename T, size_t CapacityLhs, typename V, size_t Size>
|
||||||
|
bool operator==(const FixedCapacityContainer<T, CapacityLhs> &lhs,
|
||||||
|
const std::array<V, Size> &rhs) {
|
||||||
|
return lhs.is_equal(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t Size, typename V, size_t CapacityRhs>
|
||||||
|
bool operator==(const std::array<T, Size> &lhs,
|
||||||
|
const FixedCapacityContainer<V, CapacityRhs> &rhs) {
|
||||||
|
return rhs.is_equal(lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t CapacityLhs, typename V, size_t Size>
|
||||||
|
bool operator!=(const FixedCapacityContainer<T, CapacityLhs> &lhs,
|
||||||
|
const std::array<V, Size> &rhs) {
|
||||||
|
return !lhs.is_equal(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t Size, typename V, size_t CapacityRhs>
|
||||||
|
bool operator!=(const std::array<T, Size> &lhs,
|
||||||
|
const FixedCapacityContainer<V, CapacityRhs> &rhs) {
|
||||||
|
return !rhs.is_equal(lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare with vector
|
||||||
|
|
||||||
|
template <typename T, size_t CapacityLhs, typename V>
|
||||||
|
bool operator==(const FixedCapacityContainer<T, CapacityLhs> &lhs,
|
||||||
|
const std::vector<V> &rhs) {
|
||||||
|
return lhs.is_equal(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename V, size_t CapacityRhs>
|
||||||
|
bool operator==(const std::vector<T> &lhs,
|
||||||
|
const FixedCapacityContainer<V, CapacityRhs> &rhs) {
|
||||||
|
return rhs.is_equal(lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t CapacityLhs, typename V>
|
||||||
|
bool operator!=(const FixedCapacityContainer<T, CapacityLhs> &lhs,
|
||||||
|
const std::vector<V> &rhs) {
|
||||||
|
return !lhs.is_equal(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename V, size_t CapacityRhs>
|
||||||
|
bool operator!=(const std::vector<T> &lhs,
|
||||||
|
const FixedCapacityContainer<V, CapacityRhs> &rhs) {
|
||||||
|
return !rhs.is_equal(lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** support flipped order compare */
|
/** support flipped order compare */
|
||||||
template <typename T, size_t Capacity, typename C>
|
// template <typename T, size_t Capacity, typename C>
|
||||||
typename std::enable_if<is_container<C>::value, bool>::type operator!=(
|
// typename std::enable_if<is_container<C>::value, bool>::type operator==(
|
||||||
const C &container,
|
// const C &container,
|
||||||
const FixedCapacityContainer<T, Capacity> &fixed_container) noexcept {
|
// const FixedCapacityContainer<T, Capacity> &fixed_container) noexcept {
|
||||||
return fixed_container.operator!=(container);
|
// return fixed_container.operator==(container);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// /** support flipped order compare */
|
||||||
|
// template <typename T, size_t Capacity, typename C>
|
||||||
|
// typename std::enable_if<is_container<C>::value, bool>::type operator!=(
|
||||||
|
// const C &container,
|
||||||
|
// const FixedCapacityContainer<T, Capacity> &fixed_container) noexcept {
|
||||||
|
// return fixed_container.operator!=(container);
|
||||||
|
// }
|
||||||
|
|
||||||
} // namespace sls
|
} // namespace sls
|
||||||
|
@ -10,6 +10,21 @@ TEST_CASE("FixedCapacityContainer is a container") {
|
|||||||
REQUIRE(sls::is_container<FixedCapacityContainer<int, 7>>::value == true);
|
REQUIRE(sls::is_container<FixedCapacityContainer<int, 7>>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Comparing FixedCapacity containers"){
|
||||||
|
FixedCapacityContainer<int, 5> a{0,1,2};
|
||||||
|
FixedCapacityContainer<int, 5> b{0,1,2};
|
||||||
|
FixedCapacityContainer<int, 5> c{0,1,2,4};
|
||||||
|
|
||||||
|
REQUIRE(a==b);
|
||||||
|
REQUIRE_FALSE(a!=b);
|
||||||
|
REQUIRE_FALSE(a==c);
|
||||||
|
REQUIRE(a!=c);
|
||||||
|
REQUIRE(c!=a);
|
||||||
|
REQUIRE_FALSE(c==a);
|
||||||
|
REQUIRE_FALSE(b==c);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Compare array and fixed capacity container") {
|
TEST_CASE("Compare array and fixed capacity container") {
|
||||||
std::array<int, 3> arr{1, 2, 3};
|
std::array<int, 3> arr{1, 2, 3};
|
||||||
std::array<int, 3> arr2{1, 7, 3};
|
std::array<int, 3> arr2{1, 7, 3};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user