diff --git a/Examples/src/HeapView/heapViewTraits.hpp b/Examples/src/HeapView/heapViewTraits.hpp new file mode 100644 index 000000000..673de6812 --- /dev/null +++ b/Examples/src/HeapView/heapViewTraits.hpp @@ -0,0 +1,45 @@ +// +// Created by forma on 20/06/23. +// + +#ifndef EXAMPLES_HEAPVIEWTRAITS_HPP +#define EXAMPLES_HEAPVIEWTRAITS_HPP +#include +#include + + +namespace apsc +{ + +/*! +@brief Traits for the heapView class +@tparam DataElementType The type of the elements stored in the heap +*/ +template +struct heapViewTraits +{ + //! The type of the index + using Index = typename std::vector::size_type; + //! The type of the vector storing the data + using DataVector = std::vector; + //! The type of the indixes of the heap (it is the same as the type of the indexes of the data vector) + using DataIndex = Index; + /*! The type of the elements stored in the heap. + * It is the same as the type of the elements stored in the data vector + * @note We need a comparison operator on this type + */ + using ElementType = DataElementType; + /*! The internal structure keeping the indexes of the heap + * + * HeapIndex(i) returns the index of the i-th element in the heap + */ + using HeapIndex = std::vector; + /*! An internal structure storing the indexes of the data vector + * HeapIter(i) returns the index of the i-th heap element in the data vector + * We have HeapIndex(HeapIter(i))=i if i is a valid index of the heap + */ + using HeapIter = std::vector>; +}; + +} // namespace apsc +#endif // EXAMPLES_HEAPVIEWTRAITS_HPP diff --git a/Examples/src/RKFSolver/ButcherRKF.hpp b/Examples/src/RKFSolver/ButcherRKF.hpp index 145db6d05..777cfce68 100644 --- a/Examples/src/RKFSolver/ButcherRKF.hpp +++ b/Examples/src/RKFSolver/ButcherRKF.hpp @@ -55,6 +55,8 @@ template struct ButcherArray /*! * Check if it correspond to an implicit RK scheme * @return true if implicit + * @todo try to do it in the constructor. I need to check if it is possible to + * maintain it constexpr * */ constexpr bool diff --git a/Examples/src/STL/Optional/main_optional.cpp b/Examples/src/STL/Optional/main_optional.cpp index 5c3f35181..1b648385b 100644 --- a/Examples/src/STL/Optional/main_optional.cpp +++ b/Examples/src/STL/Optional/main_optional.cpp @@ -24,6 +24,7 @@ countValid(V const &v) if(x) ++count; }); + std::cout << "The container has " << count << " valid elements:\n"; for(auto &x : v) if(x) // valid @@ -52,7 +53,9 @@ main() std::cout << "v[2] stores no value" << std::endl; v[2] = 20.0; countValid(v); - if(v[2].has_value()) + + // You may also exploit the fact that a std::optional converts to bool + if(v[2]) std::cout << "v[2] stores " << v[2].value() << std::endl; else std::cout << "v[2] stores no value" << std::endl;