ENH: add explicit flipBoolOp, tighten access on pass-through (noOp) version

- the noOp now returns const reference, noexcept
This commit is contained in:
Mark Olesen
2019-11-20 19:48:09 +01:00
committed by Andrew Heather
parent 2d7bad2d2e
commit cd366b60cc
2 changed files with 22 additions and 16 deletions

View File

@ -29,8 +29,7 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<> template<> Foam::scalar Foam::flipOp::operator()(const scalar& v) const
Foam::scalar Foam::flipOp::operator()(const scalar& v) const
{ {
return -v; return -v;
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2016 OpenFOAM Foundation Copyright (C) 2015-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,7 +28,7 @@ Class
Foam::flipOp Foam::flipOp
Description Description
Class containing functor to negate primitives. Dummy for all other types. Functor to negate primitives. Dummy for most other types.
Used in mesh transformations where face can flip. Used in mesh transformations where face can flip.
@ -50,34 +51,40 @@ namespace Foam
Class flipOp Declaration Class flipOp Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class flipOp struct flipOp
{ {
public: template<class T>
T operator()(const T& val) const
template<class Type>
Type operator()(const Type& val) const
{ {
return val; return val;
} }
}; };
class noOp //- Pass through value. Should never be specialized.
struct noOp
{ {
public: template<class T>
const T& operator()(const T& val) const noexcept
template<class Type>
Type operator()(const Type& val) const
{ {
return val; return val;
} }
}; };
class flipLabelOp //- Invert boolean value
struct flipBoolOp
{ {
public: bool operator()(const bool& val) const noexcept
{
return !val;
}
};
//- Negate integer values
struct flipLabelOp
{
label operator()(const label& val) const label operator()(const label& val) const
{ {
return -val; return -val;