Skip to content

Commit

Permalink
few fixes and bettered doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lformaggia committed Apr 16, 2024
1 parent ac88fbd commit 779f1b0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
45 changes: 45 additions & 0 deletions Examples/src/HeapView/heapViewTraits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Created by forma on 20/06/23.
//

#ifndef EXAMPLES_HEAPVIEWTRAITS_HPP
#define EXAMPLES_HEAPVIEWTRAITS_HPP
#include <vector>
#include <optional>


namespace apsc
{

/*!
@brief Traits for the heapView class
@tparam DataElementType The type of the elements stored in the heap
*/
template <class DataElementType>
struct heapViewTraits
{
//! The type of the index
using Index = typename std::vector<DataElementType>::size_type;
//! The type of the vector storing the data
using DataVector = std::vector<DataElementType>;
//! 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<Index>;
/*! 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<std::optional<Index>>;
};

} // namespace apsc
#endif // EXAMPLES_HEAPVIEWTRAITS_HPP
2 changes: 2 additions & 0 deletions Examples/src/RKFSolver/ButcherRKF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ template <unsigned int NSTAGES> 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
Expand Down
5 changes: 4 additions & 1 deletion Examples/src/STL/Optional/main_optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<T> 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;
Expand Down

0 comments on commit 779f1b0

Please sign in to comment.