namespace func

Overview

Contains common lambda functions. More…

namespace func {

// global variables

const auto GetId = [](const auto&obj) { return obj.GetId(); };
const auto GetPtrId = [](const auto&obj) { return obj->GetId(); };
const auto OptValue = [](const auto&obj) { return obj.value(); };
const auto OptHasValue = [](const auto&obj) { return obj.has_value(); };
const auto Is = [](const auto&obj)->bool { return obj; };
const auto IsNullptr = [](const auto&obj)->bool { return obj == nullptr; };
const auto IsNotNullptr = [](const auto&obj)->bool { return obj != nullptr; };
const auto IsEmpty = [](const auto&obj)->bool { return obj.empty(); };
const auto IsNotEmpty = [](const auto&obj)->bool { return !obj.empty(); };
const auto GetSize = [](const auto&obj)->std::size_t { return obj.size(); };
const auto GetFirst = [](const auto&pair) { return pair.first; };
const auto GetSecond = [](const auto&pair) { return pair.second; };
const auto IfNotNull = [](const auto&obj_ptr, const auto Func) { if(obj_ptr != nullptr) { Func(*obj_ptr); } };
const auto GetX = [](const auto&o) { return o.x; };
const auto GetY = [](const auto&o) { return o.y; };
const auto StaticCast = [](const TypeIn&value) { return static_cast<TypeOut>(value); };

} // namespace func

Detailed Documentation

Contains common lambda functions.

Global Variables

const auto GetId = [](const auto&obj) { return obj.GetId(); }

Lambda function that uses ‘GetId’ function to get object’s id.

Applies to any object that has a GetId() function.

const auto GetPtrId = [](const auto&obj) { return obj->GetId(); }

Lambda function that uses ‘GetId’ function to get object’s id.

Applies to any pointer to an object that has a GetId() function.

const auto OptValue = [](const auto&obj) { return obj.value(); }

Lambda function that gets std::optional’s value.

Applies to std::optional.

const auto OptHasValue = [](const auto&obj) { return obj.has_value(); }

Lambda function that returns whether a std::optional has value.

Applies to std::optional.

const auto Is = [](const auto&obj)->bool { return obj; }

Lambda function that casts the object to bool.

Applies to all objects that can be cast/compared to bool.

const auto IsNullptr = [](const auto&obj)->bool { return obj == nullptr; }

Lambda function that return whether the object is null pointer.

Applies to pointers.

const auto IsNotNullptr = [](const auto&obj)->bool { return obj != nullptr; }

Lambda function that return whether the object is not a null pointer.

Applies to pointers.

const auto IsEmpty = [](const auto&obj)->bool { return obj.empty(); }

Lambda function that returns whether the object is empty.

Applies to any object that has an empty() function. (std::vector, std::string…).

const auto IsNotEmpty = [](const auto&obj)->bool { return !obj.empty(); }

Lambda function that returns whether the object is not empty.

Applies to any object that has an empty() function. (std::vector, std::string…).

const auto GetSize = [](const auto&obj)->std::size_t { return obj.size(); }

Lambda function that returns the size of an object.

Applies to any object that has a size() function. (std::vector…).

const auto GetFirst = [](const auto&pair) { return pair.first; }

Lambda function that returns the first element in a pair.

applies to std::pair.

const auto GetSecond = [](const auto&pair) { return pair.second; }

Lambda function that returns the second element in a pair.

applies to std::pair.

const auto IfNotNull = [](const auto&obj_ptr, const auto Func) { if(obj_ptr != nullptr) { Func(*obj_ptr); } }

Lambda function that performs a callback on an if it is nor null. Otherwise it ignores it.

const auto GetX = [](const auto&o) { return o.x; }

Lambda function that return the x value of an object.

const auto GetY = [](const auto&o) { return o.y; }

Lambda function that return the x value of an object.

const auto StaticCast = [](const TypeIn&value) { return static_cast<TypeOut>(value); }

StaticCast a value to a different type.