diff --git a/CMakeLists.txt b/CMakeLists.txt index ab0c1dac6..a1a568e98 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ option (SLS_USE_TESTS "TESTS" OFF) option (SLS_USE_INTEGRATION_TESTS "Integration Tests" OFF) option(SLS_USE_SANITIZER "Sanitizers for debugging" OFF) option(SLS_USE_PYTHON "Python bindings" OFF) +option(SLS_BUILD_DOCS "Documentations" OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) @@ -182,10 +183,11 @@ configure_file( .clang-tidy ) -add_subdirectory(sample) - -add_subdirectory(docs) +#add_subdirectory(sample) +if(SLS_BUILD_DOCS) + add_subdirectory(docs) +endif(SLS_BUILD_DOCS) diff --git a/slsSupportLib/include/FixedCapacityContainer.h b/slsSupportLib/include/FixedCapacityContainer.h index 443426336..ea409ec22 100644 --- a/slsSupportLib/include/FixedCapacityContainer.h +++ b/slsSupportLib/include/FixedCapacityContainer.h @@ -16,34 +16,28 @@ template class FixedCapacityContainer { using const_iterator = typename std::array::const_iterator; FixedCapacityContainer() = default; - explicit FixedCapacityContainer(std::initializer_list l) { - current_size = l.size(); + + explicit FixedCapacityContainer(std::initializer_list l) + : current_size(l.size()) { + size_check(l.size()); std::copy(l.begin(), l.end(), data_.begin()); } + /** Copy construct from another container */ template ::value && + is_container::value && std::is_same::value>::type> - explicit FixedCapacityContainer(const V &v) { - if (v.size() > Capacity) { - throw std::runtime_error( - "Capacity needs to be same size or larger than vector"); - } - current_size = v.size(); + FixedCapacityContainer(const V &v) : current_size(v.size()) { + size_check(v.size()); std::copy(v.begin(), v.end(), data_.begin()); } - template - explicit FixedCapacityContainer( - const FixedCapacityContainer &other) noexcept { - static_assert(Capacity >= OtherCapacity, - "Container needs to be same size or larger"); - current_size = other.size(); - std::copy(other.cbegin(), other.cend(), data_.begin()); - } - - FixedCapacityContainer &operator=(const std::vector &other) { + /** copy assignment from another container */ + template + typename std::enable_if::value, FixedCapacityContainer &>::type + operator=(const V &other) { + size_check(other.size()); std::copy(other.begin(), other.end(), data_.begin()); current_size = other.size(); return *this; @@ -119,6 +113,13 @@ template class FixedCapacityContainer { private: size_type current_size{}; std::array data_; + + void size_check(size_type s) const { + if (s > Capacity) { + throw std::runtime_error( + "Capacity needs to be same size or larger than vector"); + } + } } __attribute__((packed)); /* Free function concerning FixedCapacityContainer */ diff --git a/slsSupportLib/tests/test-FixedCapacityContainer.cpp b/slsSupportLib/tests/test-FixedCapacityContainer.cpp index 4d3552e6f..53ae2fbb8 100644 --- a/slsSupportLib/tests/test-FixedCapacityContainer.cpp +++ b/slsSupportLib/tests/test-FixedCapacityContainer.cpp @@ -17,12 +17,39 @@ TEST_CASE("Construct from vector"){ REQUIRE(fcc == vec); } +TEST_CASE("Copy construct from vector"){ + std::vector vec{1,2,3}; + FixedCapacityContainer fcc = vec; + REQUIRE(fcc == vec); +} + +TEST_CASE("Copy assignment from vector"){ + std::vector vec{1,2,3}; + FixedCapacityContainer fcc; + fcc = vec; + REQUIRE(fcc == vec); +} + + TEST_CASE("Construct from array"){ std::array arr{1,2,3}; FixedCapacityContainer fcc{arr}; REQUIRE(fcc == arr); } +TEST_CASE("Copy assign from array"){ + std::array arr{1,2,3}; + FixedCapacityContainer fcc; + fcc = arr; + REQUIRE(fcc == arr); +} + +TEST_CASE("Copy construct from array"){ + std::array arr{1,2,3}; + FixedCapacityContainer fcc = arr; + REQUIRE(fcc == arr); +} + SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { GIVEN("A default constructed container") {