Skip to content
Snippets Groups Projects
Commit dc0cde51 authored by Carsten Gräser's avatar Carsten Gräser
Browse files

[cleanup][bugfix] Reimplement operator<< for MultiTypeBlockVector

Reimplement this using Hybrid::forEach. Along the way this
also fixes the bug that operator<< ignores the passed stream
and uses std::cout instead.
parent 53d437bb
No related branches found
No related tags found
1 merge request!45Use hybridutilities
......@@ -31,40 +31,6 @@ namespace Dune {
/**
@brief prints out a vector (type MultiTypeBlockVector)
The parameter "current_element" is the index of
the element to be printed out. Via recursive calling
all other elements (number is "remaining_elements")
are printed, too. This is internally called when
a MultiTypeBlockVector object is passed to an output stream.
Example:
\code
MultiTypeBlockVector<int,int> CVect;
std::cout << CVect;
\endcode
*/
template<int current_element, int remaining_elements, typename TVec>
class MultiTypeBlockVector_Print {
public:
/**
* print out the current vector element and all following
*/
static void print(const TVec& v) {
std::cout << "\t(" << current_element << "):\n" << std::get<current_element>(v) << "\n";
MultiTypeBlockVector_Print<current_element+1,remaining_elements-1,TVec>::print(v); //next element
}
};
template<int current_element, typename TVec> //recursion end (remaining_elements=0)
class MultiTypeBlockVector_Print<current_element,0,TVec> {
public:
static void print(const TVec&) {std::cout << "\n";}
};
/**
@brief Add/subtract second vector to/from the first (v1 += v2)
......@@ -410,7 +376,10 @@ namespace Dune {
*/
template <typename... Args>
std::ostream& operator<< (std::ostream& s, const MultiTypeBlockVector<Args...>& v) {
MultiTypeBlockVector_Print<0,sizeof...(Args),MultiTypeBlockVector<Args...> >::print(v);
using namespace Dune::Hybrid;
forEach(integralRange(size(v)), [&](auto&& i) {
s << "\t(" << i << "):\n" << v[i] << "\n";
});
return s;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment