mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-22 18:50:41 +02:00
rewrote end() for StaticVector
This commit is contained in:
parent
1d0eeea7ee
commit
30eab42294
@ -113,10 +113,10 @@ template <typename T, size_t Capacity> class StaticVector {
|
|||||||
// auto begin() noexcept -> decltype(data_.begin()) { return data_.begin();
|
// auto begin() noexcept -> decltype(data_.begin()) { return data_.begin();
|
||||||
// }
|
// }
|
||||||
const_iterator begin() const noexcept { return data_.begin(); }
|
const_iterator begin() const noexcept { return data_.begin(); }
|
||||||
iterator end() noexcept { return &data_[current_size]; }
|
iterator end() noexcept { return data_.begin()+current_size; }
|
||||||
const_iterator end() const noexcept { return &data_[current_size]; }
|
const_iterator end() const noexcept { return data_.begin()+current_size; }
|
||||||
const_iterator cbegin() const noexcept { return data_.cbegin(); }
|
const_iterator cbegin() const noexcept { return data_.cbegin(); }
|
||||||
const_iterator cend() const noexcept { return &data_[current_size]; }
|
const_iterator cend() const noexcept { return data_.cbegin()+current_size; }
|
||||||
|
|
||||||
void size_check(size_type s) const {
|
void size_check(size_type s) const {
|
||||||
if (s > Capacity) {
|
if (s > Capacity) {
|
||||||
|
@ -8,12 +8,15 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace sls {
|
|
||||||
|
using sls::StaticVector;
|
||||||
|
|
||||||
TEST_CASE("StaticVector is a container") {
|
TEST_CASE("StaticVector is a container") {
|
||||||
REQUIRE(is_container<StaticVector<int, 7>>::value == true);
|
REQUIRE(sls::is_container<StaticVector<int, 7>>::value == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("Comparing StaticVector containers") {
|
TEST_CASE("Comparing StaticVector containers") {
|
||||||
StaticVector<int, 5> a{0, 1, 2};
|
StaticVector<int, 5> a{0, 1, 2};
|
||||||
StaticVector<int, 5> b{0, 1, 2};
|
StaticVector<int, 5> b{0, 1, 2};
|
||||||
@ -90,10 +93,17 @@ TEST_CASE("Copy construct from array") {
|
|||||||
REQUIRE(fcc == arr);
|
REQUIRE(fcc == arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Construct from a smaller StaticVector") {
|
||||||
|
StaticVector<int, 3> sv{1, 2, 3};
|
||||||
|
StaticVector<int, 5> sv2{sv};
|
||||||
|
REQUIRE(sv == sv2);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("Free function and method gives the same iterators") {
|
TEST_CASE("Free function and method gives the same iterators") {
|
||||||
StaticVector<int, 3> fcc{1, 2, 3};
|
StaticVector<int, 3> fcc{1, 2, 3};
|
||||||
REQUIRE(std::begin(fcc) == fcc.begin());
|
REQUIRE(std::begin(fcc) == fcc.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
SCENARIO("StaticVectors can be sized and resized", "[support]") {
|
SCENARIO("StaticVectors can be sized and resized", "[support]") {
|
||||||
|
|
||||||
GIVEN("A default constructed container") {
|
GIVEN("A default constructed container") {
|
||||||
@ -246,23 +256,23 @@ SCENARIO("Sorting, removing and other manipulation of a container",
|
|||||||
REQUIRE(a[3] == 90);
|
REQUIRE(a[3] == 90);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// WHEN("Sorting is done using free function for begin and end") {
|
WHEN("Sorting is done using free function for begin and end") {
|
||||||
// std::sort(begin(a), end(a));
|
std::sort(std::begin(a), std::end(a));
|
||||||
// THEN("it also works") {
|
THEN("it also works") {
|
||||||
// REQUIRE(a[0] == 12);
|
REQUIRE(a[0] == 12);
|
||||||
// REQUIRE(a[1] == 12);
|
REQUIRE(a[1] == 12);
|
||||||
// REQUIRE(a[2] == 14);
|
REQUIRE(a[2] == 14);
|
||||||
// REQUIRE(a[3] == 90);
|
REQUIRE(a[3] == 90);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// WHEN("Erasing elements of a certain value") {
|
WHEN("Erasing elements of a certain value") {
|
||||||
// a.erase(std::remove(begin(a), end(a), 12));
|
a.erase(std::remove(std::begin(a), std::end(a), 12));
|
||||||
// THEN("all elements of that value are removed") {
|
THEN("all elements of that value are removed") {
|
||||||
// REQUIRE(a.size() == 2);
|
REQUIRE(a.size() == 2);
|
||||||
// REQUIRE(a[0] == 14);
|
REQUIRE(a[0] == 14);
|
||||||
// REQUIRE(a[1] == 90);
|
REQUIRE(a[1] == 90);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,4 +345,3 @@ TEST_CASE("StaticVector stream") {
|
|||||||
REQUIRE(oss.str() == "[33, 85667, 2]");
|
REQUIRE(oss.str() == "[33, 85667, 2]");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sls
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user