Commit 58ebcd51 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Add treepath literal _tp and a test

parent ba263fc2
#pragma once
#include <cassert>
#include <sstream>
#include <string>
#include <type_traits>
......@@ -10,6 +11,7 @@
#include <dune/typetree/typetraits.hh>
#include <amdis/common/Apply.hpp>
#include <amdis/common/Literals.hpp>
#include <amdis/common/Logical.hpp>
namespace AMDiS {
......@@ -150,6 +152,14 @@ auto makeTreePath(Dune::TypeTree::StaticTreePath<I...>)
#endif // DOXYGEN
/// Literal to create treepath, e.g. 021_tp -> HybridTreePath<index_t<0>,index_t<2>,index_t<1>>
template <char... digits>
constexpr auto operator"" _tp()
{
return Dune::TypeTree::hybridTreePath(std::integral_constant<std::size_t,Impl::char2digit(digits)>{}...);
}
// convert a treepath into a string, comma-separated
template <class... T>
std::string to_string(Dune::TypeTree::HybridTreePath<T...> const& tp)
......
......@@ -10,6 +10,16 @@
using namespace AMDiS;
using namespace Dune::Indices;
template <class... I, class... J,
std::enable_if_t<(sizeof...(I) == sizeof...(J)), int> =0>
bool compare(Dune::TypeTree::HybridTreePath<I...> const& tp1, Dune::TypeTree::HybridTreePath<J...> const& tp2)
{
return Ranges::applyIndices<sizeof...(I)>([&](auto... i) {
return ((tp1[i] == tp2[i]) &&...);
});
}
int main (int argc, char** argv)
{
Environment env(argc, argv);
......@@ -36,4 +46,11 @@ int main (int argc, char** argv)
auto tp = Dune::TypeTree::hybridTreePath(1u, _2);
static_assert( std::is_same_v<TYPEOF(tp), TYPEOF(makeTreePath(tp))> );
AMDIS_TEST(compare(tp, 12_tp));
AMDIS_TEST(compare(makeTreePath(1,2), 12_tp));
AMDIS_TEST(compare(makeTreePath(0,1,2), 012_tp));
AMDIS_TEST(compare(makeTreePath(0,0,1,2), 0012_tp));
return report_errors();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment