Skip to content
Snippets Groups Projects
Commit 638e649a authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

Resolve concept loops with functions

This commit replaces the lambda in unevaluated contexts with an explicit function. This makes the code more portable as there is no need for a compiler that supports [temp.deduct/9], for example, Apple Clang 15. On the other hand it makes the code slightly less readable.
parent f8257fdb
No related branches found
No related tags found
1 merge request!726Resolve concept loops with functions
Pipeline #67628 passed
......@@ -13,10 +13,6 @@
* In order to enable these concepts, you need the following:
* (i) A C++20 compiler with concepts (i.e. __cpp_concepts >= 201907L)
* (ii) The concepts in the standard library (i.e. __cpp_lib_concepts >= 202002L)
* (iii) A C++ compiler that supports unevaluated context lambdas (i.e.
* can compile `using = decltype([]{})`). This is automatically tested by
* CMake and exposed as a macro definition
* `DUNE_HAVE_CXX_UNEVALUATED_CONTEXT_LAMBDA`.
*
* - `gcc>=9` and `clang>=12` are known to fulfill (i) and (iii).
* - `libstdc++>10` and `libc++>=13` are known to fulfill (ii).
......@@ -25,7 +21,7 @@
// check whether c++20 concept can be used
#if __has_include(<version>) && __has_include(<concepts>)
#include <version>
#if __cpp_concepts >= 201907L && __cpp_lib_concepts >= 202002L && DUNE_HAVE_CXX_UNEVALUATED_CONTEXT_LAMBDA
#if __cpp_concepts >= 201907L && __cpp_lib_concepts >= 202002L
#ifndef DUNE_GRID_HAVE_CONCEPTS
#define DUNE_GRID_HAVE_CONCEPTS 1
#endif
......
......@@ -8,9 +8,9 @@
#include <concepts>
#include <utility>
#include <dune/common/rangeutilities.hh>
#include <dune/geometry/type.hh>
#include <dune/grid/common/gridenums.hh>
#include <dune/grid/concepts/entity.hh>
#include <dune/grid/concepts/geometry.hh>
#include <dune/grid/concepts/archetypes/entity.hh>
......@@ -62,12 +62,9 @@ namespace Impl {
{ e.template subEntity<codim>(subEntity) } -> EntityGeneral;
};
template<class E, int first, int last>
concept EntityAllCodimsExtended = requires(std::make_integer_sequence<int,last-first> codims)
{
[]<int... c>(std::integer_sequence<int,c...>)
requires (EntityCodimExtended<E,(first+c)> &&...) {} (codims);
};
template<typename E, std::size_t... c>
void entityAllCodimsExtended(std::integer_sequence<std::size_t,c...>)
requires (EntityCodimExtended<E,int(c)> &&...);
} // end namespace Impl
......@@ -96,7 +93,9 @@ requires(const E e, int maxLevel)
requires std::same_as<E, typename E::template Codim<0>::Entity>;
} &&
Impl::EntityCodimExtended<E,0> &&
Impl::EntityAllCodimsExtended<E,1,E::dimension+1>;
requires (index_constant<1> from, index_constant<E::dimension+1> to) {
Impl::entityAllCodimsExtended<E>(range(from, to).indices());
};
/**
* @brief Model of a grid entity
......
......@@ -66,12 +66,9 @@ namespace Impl {
};
} && GridCodimAllPartitions<G,codim>;
template<class G, int first, int last>
concept GridAllCodims = requires(std::make_integer_sequence<int,last-first> codims)
{
[]<int... c>(std::integer_sequence<int,c...>)
requires (GridCodim<G,(first+c)> &&...) {} (codims);
};
template<class G, std::size_t... c>
void gridAllCodims(std::index_sequence<c...>)
requires (GridCodim<G,int(c)> &&...);
} // end namespace Impl
......@@ -149,7 +146,9 @@ requires(const G cg, int level, int codim, Dune::GeometryType type)
};
} &&
Impl::GridCodim<G,0> &&
Impl::GridAllCodims<G,1,G::dimension+1>;
requires (index_constant<1> from, index_constant<G::dimension+1> to) {
Impl::gridAllCodims<G>(range(from, to).indices());
};
} // end namespace Dune::Concept
......
......@@ -64,12 +64,11 @@ namespace Impl {
requires (not Dune::Capabilities::hasEntityIterator<Grid,codim>::v)
void requireGridViewCodim() {}
template <class GV, int first, int last>
concept GridViewAllCodims = requires(std::make_integer_sequence<int,last-first> codims)
{
[]<int... c>(std::integer_sequence<int,c...>) requires
requires { (requireGridViewCodim<GV,typename GV::Grid,(first+c)>(),...); } {} (codims);
};
template <class GV, std::size_t... c>
void gridViewAllCodims(std::index_sequence<c...>)
requires requires {
(requireGridViewCodim<GV,typename GV::Grid,int(c)>(),...);
};
} // end namespace Impl
......@@ -105,7 +104,9 @@ requires(const GV gv, int codim, Dune::GeometryType type)
};
} &&
Impl::GridViewCodim<GV,0> &&
Impl::GridViewAllCodims<GV,1,GV::dimension+1>;
requires (index_constant<1> from, index_constant<GV::dimension+1> to) {
Impl::gridViewAllCodims<GV>(range(from, to).indices());
};
} // end namespace Dune::Concept
......
......@@ -28,12 +28,9 @@ namespace Impl {
{ is.contains(entity) } -> std::convertible_to<bool>;
};
template<class IS, int first, int last>
concept IndexSetEntityAllCodims = requires(std::make_integer_sequence<int,last-first> codims)
{
[]<int... c>(std::integer_sequence<int,c...>)
requires (IndexSetEntityCodim<IS,(first+c)> &&...) {} (codims);
};
template<class IS, std::size_t... c>
void indexSetEntityAllCodims(std::integer_sequence<std::size_t,c...>)
requires (IndexSetEntityCodim<IS,int(c)> &&...);
} // end namespace Impl
......@@ -56,8 +53,9 @@ concept IndexSet = requires(const IS is, Dune::GeometryType type, int codim)
{ is.size(codim) } -> std::convertible_to<typename IS::IndexType>;
} &&
Impl::IndexSetEntityCodim<IS,0> &&
Impl::IndexSetEntityAllCodims<IS,1,IS::dimension+1>;
requires (index_constant<1> from, index_constant<IS::dimension+1> to) {
Impl::indexSetEntityAllCodims<IS>(range(from, to).indices());
};
namespace Impl {
......@@ -69,12 +67,9 @@ namespace Impl {
{ is.id(entity) } -> std::same_as<typename IS::IdType>;
};
template<class IS, int first, int last>
concept IdSetEntityAllCodims = requires(std::make_integer_sequence<int,last-first> codims)
{
[]<int... c>(std::integer_sequence<int,c...>)
requires (IdSetEntityCodim<IS,(first+c)> &&...) {} (codims);
};
template<class IS, std::size_t... c>
void idSetEntityAllCodims(std::integer_sequence<std::size_t,c...>)
requires (IdSetEntityCodim<IS,int(c)> &&...);
} // end namespace Impl
......@@ -92,7 +87,9 @@ concept IdSet = requires(const IS is, const typename IS::template Codim<0>::Enti
{ is.subId(entity,i,cc) } -> std::same_as<typename IS::IdType>;
} &&
Impl::IdSetEntityCodim<IS,0> &&
Impl::IdSetEntityAllCodims<IS,1,IS::dimension+1>;
requires (index_constant<1> from, index_constant<IS::dimension+1> to) {
Impl::idSetEntityAllCodims<IS>(range(from, to).indices());
};
} // end namespace Dune::Concept
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment