Skip to content
Snippets Groups Projects
Commit af2ad4ec authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos Committed by Simon Praetorius
Browse files

Use Hybrid::equal_to instead of Hybrid::equals

parent 3fd176b8
No related branches found
No related tags found
2 merge requests!1470Fix wrong variable name to make target hash (2.10),!1410Use Hybrid::equal_to instead of Hybrid::equals
......@@ -17,7 +17,7 @@ In order to build the DUNE core modules you need at least the following software
- Python: Add `TupleVector` Python bindings
- Python: The function `cppType` now support Python tuples, which are converted to the C++ type `std::tuple`
- Python: The function `cppType` now support Python tuples, which are converted to the C++ type `std::tuple`
- `TupleVector` now implements the standard protocol for tuple-like types.
......@@ -59,7 +59,7 @@ In order to build the DUNE core modules you need at least the following software
- Add user-defined literals `_ic`, `_uc` and `_sc` to represent integral constants.
- Add "hybrid" functors for basic math operations with integral constant arguments, i.e.,
`Hybrid::max`, `Hybrid::min`, `Hybrid::plus`, `Hybrid::minus`, and `Hybrid::equals`. Operations
`Hybrid::max`, `Hybrid::min`, `Hybrid::plus`, `Hybrid::minus`, and `Hybrid::equal_to`. Operations
between two integral constants result in an integral constant, whereas operations with at least
one non integral constant argument is performed on the underlying value type.
......
......@@ -562,14 +562,30 @@ inline constexpr auto minus = hybridFunctor(std::minus<>{});
* \code{.cpp}
* using namespace Dune::Indices;
* { // hybrid transformation!
* auto j = Dune::Hybrid::equals( 2, 1); // -> false
* auto j = Dune::Hybrid::equals( 2, _1); // -> false
* auto k = Dune::Hybrid::equals(_2, _1); // -> std::false_type
* auto j = Dune::Hybrid::equal_to( 2, 1); // -> false
* auto j = Dune::Hybrid::equal_to( 2, _1); // -> false
* auto k = Dune::Hybrid::equal_to(_2, _1); // -> std::false_type
* // independent of the context, `k` encodes its value in the type system
* }
* \endcode
*/
inline constexpr auto equals = hybridFunctor(std::equal_to<>{});
inline constexpr auto equal_to = hybridFunctor(std::equal_to<>{});
/**
* \brief Equality comparison
*
* \ingroup HybridUtilities
*
* If both types have a static member value, the result of comparing
* these is returned as std::integral_constant<bool, *>. Otherwise
* the result of a runtime comparison of t1 and t2 is directly returned.
*/
template<class T1, class T2>
constexpr auto equals(T1&& t1, T2&& t2){
return equal_to(std::forward<T1>(t1), std::forward<T2>(t2));
}
namespace Impl {
......
......@@ -36,7 +36,7 @@ auto incAndAppendToFirst(C&& c)
forEach(integralRange(Dune::Hybrid::size(c)), [&](auto&& i) {
using namespace Dune::Hybrid;
using namespace Dune::Indices;
ifElse(equals(i, _0), [&](auto id) {
ifElse(equal_to(i, _0), [&](auto id) {
id(c[i]).append("+1");
}, [&](auto id) {
++id(c[i]);
......@@ -174,26 +174,26 @@ int main()
Dune::TestSuite test;
using namespace Dune::Indices;
static_assert(Dune::Hybrid::equals(_1, _1));
static_assert(not Dune::Hybrid::equals(_1, _2));
static_assert(Dune::Hybrid::equal_to(_1, _1));
static_assert(not Dune::Hybrid::equal_to(_1, _2));
static_assert(Dune::Hybrid::equals(1, _1));
test.check(Dune::Hybrid::equals(one, one)) << "Runtime Hybrid::equals failed.";
static_assert(Dune::Hybrid::equal_to(1, _1));
test.check(Dune::Hybrid::equal_to(one, one)) << "Runtime Hybrid::equal_to failed.";
static_assert(Dune::Hybrid::equals(_3, Dune::Hybrid::max(_1,_2,_3)));
test.check(Dune::Hybrid::equals(3, Dune::Hybrid::max(one,_2,_3)))
static_assert(Dune::Hybrid::equal_to(_3, Dune::Hybrid::max(_1,_2,_3)));
test.check(Dune::Hybrid::equal_to(3, Dune::Hybrid::max(one,_2,_3)))
<< "Runtime Hybrid::max failed.";
static_assert(Dune::Hybrid::equals(_1, Dune::Hybrid::min(_1,_2,_3)));
test.check(Dune::Hybrid::equals(one, Dune::Hybrid::min(one,_2,_3)))
static_assert(Dune::Hybrid::equal_to(_1, Dune::Hybrid::min(_1,_2,_3)));
test.check(Dune::Hybrid::equal_to(one, Dune::Hybrid::min(one,_2,_3)))
<< "Runtime Hybrid::min failed.";
static_assert(Dune::Hybrid::equals(_4, Dune::Hybrid::plus(_1,_3)));
test.check(Dune::Hybrid::equals(4, Dune::Hybrid::plus(one,_3)))
static_assert(Dune::Hybrid::equal_to(_4, Dune::Hybrid::plus(_1,_3)));
test.check(Dune::Hybrid::equal_to(4, Dune::Hybrid::plus(one,_3)))
<< "Runtime Hybrid::plus failed.";
static_assert(Dune::Hybrid::equals(_2, Dune::Hybrid::minus(_3,_1)));
test.check(Dune::Hybrid::equals(2, Dune::Hybrid::minus(_3,one)))
static_assert(Dune::Hybrid::equal_to(_2, Dune::Hybrid::minus(_3,_1)));
test.check(Dune::Hybrid::equal_to(2, Dune::Hybrid::minus(_3,one)))
<< "Runtime Hybrid::minus failed.";
incrementAll(vector);
......
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