based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit faad524e338b7a26b4fc335b893881de39a2a8c4
parent 10d02479b65711884e60d257ce102d46e9bbfa22
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Thu, 29 May 2025 19:38:28 +0200

Split functional predicates, add not_null

Diffstat:
D include/based/functional/predicate.hpp | -----------------------------------
A include/based/functional/predicate/complement.hpp | +++++++++++++++++
A include/based/functional/predicate/complement_of_converse.hpp | +++++++++++++++++
A include/based/functional/predicate/converse.hpp | +++++++++++++++++
A include/based/functional/predicate/not_null.hpp | ++++++++++++

5 files changed, 63 insertions(+), 35 deletions(-)


diff --git a/ include/based/functional/predicate.hpp b/ include/based/functional/predicate.hpp

@@ -1,35 +0,0 @@

#pragma once

#include "based/concepts/procedure/predicate.hpp"

namespace based
{

template<typename T, Relation<T> Rel>
auto complement(Rel rel)
{
return [=](const T& lhs, const T& rhs)
{
return !rel(lhs, rhs);
};
}

template<typename T, Relation<T> Rel>
auto converse(Rel rel)
{
return [=](const T& lhs, const T& rhs)
{
return rel(rhs, lhs);
};
}

template<typename T, Relation<T> Rel>
auto complement_of_converse(Rel rel)
{
return [=](const T& lhs, const T& rhs)
{
return !rel(rhs, lhs);
};
}

} // namespace based

diff --git a/ include/based/functional/predicate/complement.hpp b/ include/based/functional/predicate/complement.hpp

@@ -0,0 +1,17 @@

#pragma once

#include "based/concepts/procedure/predicate.hpp"

namespace based
{

template<typename T, Relation<T> Rel>
auto complement(Rel rel)
{
return [=](const T& lhs, const T& rhs)
{
return !rel(lhs, rhs);
};
}

} // namespace based

diff --git a/ include/based/functional/predicate/complement_of_converse.hpp b/ include/based/functional/predicate/complement_of_converse.hpp

@@ -0,0 +1,17 @@

#pragma once

#include "based/concepts/procedure/predicate.hpp"

namespace based
{

template<typename T, Relation<T> Rel>
auto complement_of_converse(Rel rel)
{
return [=](const T& lhs, const T& rhs)
{
return !rel(rhs, lhs);
};
}

} // namespace based

diff --git a/ include/based/functional/predicate/converse.hpp b/ include/based/functional/predicate/converse.hpp

@@ -0,0 +1,17 @@

#pragma once

#include "based/concepts/procedure/predicate.hpp"

namespace based
{

template<typename T, Relation<T> Rel>
auto converse(Rel rel)
{
return [=](const T& lhs, const T& rhs)
{
return rel(rhs, lhs);
};
}

} // namespace based

diff --git a/ include/based/functional/predicate/not_null.hpp b/ include/based/functional/predicate/not_null.hpp

@@ -0,0 +1,12 @@

#pragma once

namespace based
{

template<typename T>
auto not_null(const T* ptr)
{
return ptr != nullptr;
}

} // namespace based