30 #include "DGtal/base/FunctorHolder.h"
31 #include "DGtal/base/Common.h"
32 #include "DGtal/base/CUnaryFunctor.h"
34 #include "DGtalCatch.h"
37 using namespace DGtal;
48 explicit Functor(
double c) : cst(c) {}
49 inline double operator() (
double v)
const {
return v + cst; }
61 TEST_CASE(
"Holding a lambda",
"[lambda]" )
67 auto fn = [&cst] (
double v) {
return v + cst; };
72 auto holder2 = holder;
78 const auto fn = [&cst] (
double v) {
return v + cst; };
83 auto holder2 = holder;
89 auto holder =
holdFunctor( [&cst] (
double v) {
return v + cst; } );
93 auto holder2 = holder;
99 auto holder =
holdFunctor( [cst] (
double v)
mutable {
return v + cst; } );
103 auto holder2 = holder;
104 REQUIRE( holder2(0.5) == 2.0 );
109 auto holder =
holdFunctor( [] (
double v,
double c) {
return v + c; } );
111 REQUIRE( holder(0.5, 1.5) == 2.0 );
112 auto holder2 = holder;
113 REQUIRE( holder2(0.5, 1.5) == 2.0 );
117 TEST_CASE(
"Holding a functor",
"[functor]" )
128 auto holder2 = holder;
129 REQUIRE( holder2(0.5) == 2.0 );
139 auto holder2 = holder;
140 REQUIRE( holder2(0.5) == 2.0 );
149 auto holder2 = holder;
150 REQUIRE( holder2(0.5) == 2.0 );
154 TEST_CASE(
"Holding a function",
"[function]" )
162 auto holder2 = holder;
163 REQUIRE( holder2(0.5) == 2.0 );
172 auto holder2 = holder;
173 REQUIRE( holder2(0.5) == 2.0 );
177 TEST_CASE(
"Holding a std::function",
"[std::function]" )
182 std::function<double(
double)> fn =
Functor(cst);
187 auto holder2 = holder;
188 REQUIRE( holder2(0.5) == 2.0 );
functors namespace gathers all DGtal functors.
auto holdFunctor(Function &&fn) -> decltype(holdFunctorImpl(std::forward< Function >(fn), typename std::is_lvalue_reference< Function >{}))
Hold any callable object (function, functor, lambda, ...) as a C(Unary)Functor model.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Defines a unary functor, which associates arguments to results.
Go to http://www.sgi.com/tech/stl/Assignable.html.
TEST_CASE("int container traits", "[int][traits]")
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
ch add(Point(102.2, 50.2))
REQUIRE(domain.isInside(aPoint))