.\" .de Id .. .de Sp .if n .sp .if t .sp 0.4 .. .TH functor 2rheolef "rheolef-7.0" "rheolef-7.0" "rheolef-7.0" .\" label: /*Class:functor .SH NAME \fBfunctor\fP - a function wrapper suitable for field expressions .SH DESCRIPTION A \fIfunctor\fP is a class-function, i.e. a class that defines the \fBoperator()\fP: it can be used in place of an usual function. Moreover, functors can be used in Rheolef field expressions, mixed with fields (see field(2)). For instance, assuming that \fBuh\fP is a field and \fBu_ex\fP is a functor: .\" begin_example .Sp .nf Float err_l1 = integrate (omega, abs(uh - uh_ex), qopt); .Sp .fi .\" end_example where \fBomega\fP denotes a mesh (see geo(2)) and \fBqopt\fP a quadrature formula (see quadrature_option(2)). See also the integrate(4) function. An usual function \fBu_ex_f\fP cannot always be mixed so nicely in expressions, due to c++ language rules. For instance, the following exprtession is valid: .\" begin_example .Sp .nf Float err_l1 = integrate (omega, abs(uh - u_ex_f), qopt); .Sp .fi .\" end_example In some case, the compiler cannot build a field expression using usual functionsn e.g. .\" begin_example .Sp .nf Float I = integrate (omega, 0.5*u_ex_f), qopt); .Sp .fi .\" end_example because \fB0.5*u_ex_f\fP is a direct algebraic operation between usual functions and flmoating points, that is not defined in the c++ language. A way to circumvent this difficulty is to convert the usual function into a functor, as in: .\" begin_example .Sp .nf Float I = integrate (omega, 0.5*functor(u_ex_f)), qopt); .Sp .fi .\" end_example .\" skip start:AUTHOR: .\" skip start:DATE: .\" END .SH IMPLEMENTATION .\" begin_example .Sp .nf template std::function functor (R(*f)(Args...)) { return std::function(f); } .Sp .fi .\" end_example .\" LENGTH = 4 .SH SEE ALSO field(2), geo(2), quadrature_option(2), integrate(4) .SH COPYRIGHT Copyright (C) 2000-2018 Pierre Saramito GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.