Skip to content

Commit

Permalink
[Core] Clean up set_identity_function.h
Browse files Browse the repository at this point in the history
  • Loading branch information
loumalouomega authored Jul 21, 2023
1 parent 9977a67 commit af47398
Showing 1 changed file with 46 additions and 30 deletions.
76 changes: 46 additions & 30 deletions kratos/containers/set_identity_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,65 @@
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Pooyan Dadvand
//
//


#if !defined(KRATOS_SET_IDENTITY_FUNCTION_H_INCLUDED )
#define KRATOS_SET_IDENTITY_FUNCTION_H_INCLUDED


#pragma once

// System includes
#include <functional>

// External includes

// Project includes

namespace Kratos
{
///@}
///@name Kratos Classes
///@{

/// Identity function is for having the object also as key in sets
/**
*/
template<class TDataType> class SetIdentityFunction
{
public:
TDataType& operator()(TDataType& data)
{
return data;
}
const TDataType& operator()(const TDataType& data) const
{
return data;
}
};

///@}
///@name Kratos Classes
///@{

/**
* @class SetIdentityFunction
* @brief A functor that serves as the identity function.
* @details This class provides two overloaded operator() functions, one for non-const objects
* and another for const objects. The operator() returns the input object as it is,
* effectively acting as an identity function.
* The purpose of this functor is to allow objects to be used as keys in sets or other
* containers that require comparison. By using this functor, you can avoid defining
* custom comparison functions or operators when the object itself can be considered
* for comparison.
* @tparam TDataType The data type of the object that the functor operates on.
* @author Pooyan Dadvand
*/
template<class TDataType>
class SetIdentityFunction
{
public:
/**
* @brief Operator that returns a non-const reference to the input object.
* @param data The input object of type TDataType.
* @return A non-const reference to the same object as provided in the parameter.
*/
TDataType& operator()(TDataType& data)
{
return data;
}

} // namespace Kratos.
/**
* @brief Operator that returns a const reference to the input object.
* @param data The input object of type TDataType.
* @return A const reference to the same object as provided in the parameter.
*/
const TDataType& operator()(const TDataType& data) const
{
return data;
}
};

///@}

#endif // KRATOS_SET_IDENTITY_FUNCTION_H_INCLUDED defined
} // namespace Kratos.

0 comments on commit af47398

Please sign in to comment.