Utilities
Utilities header only library
Functional.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_FUNCTIONAL_H
7 #define UTILS_FUNCTIONAL_H
8 
9 #include <cstddef>
10 
12 namespace func
13 {
18  const auto GetId = [](const auto &obj) { return obj.GetId(); };
19 
24  const auto GetPtrId = [](const auto &obj) { return obj->GetId(); };
25 
30  const auto OptValue = [](const auto &obj) { return obj.value(); };
31 
36  const auto OptHasValue = [](const auto &obj) { return obj.has_value(); };
37 
42  const auto Is = [](const auto &obj)->bool { return obj; };
43 
48  const auto IsNullptr = [](const auto &obj)->bool { return obj == nullptr; };
49 
54  const auto IsNotNullptr = [](const auto &obj)->bool { return obj != nullptr; };
55 
60  const auto IsEmpty = [](const auto &obj)->bool { return obj.empty(); };
61 
66  const auto IsNotEmpty = [](const auto &obj)->bool { return !obj.empty(); };
67 
72  const auto GetSize = [](const auto &obj)->std::size_t { return obj.size(); };
73 
78  const auto GetFirst = [](const auto &pair) { return pair.first; };
79 
84  const auto GetSecond = [](const auto &pair) { return pair.second; };
85 
89  const auto IfNotNull = [](const auto &obj_ptr, const auto Func) { if (obj_ptr != nullptr) { Func(*obj_ptr); } };
90 
92  const auto GetX = [](const auto &o) { return o.x; };
93 
95  const auto GetY = [](const auto &o) { return o.y; };
96 
98  template<typename TypeIn, typename TypeOut>
99  const auto StaticCast = [](const TypeIn &value) { return static_cast<TypeOut>(value); };
100 }
101 
102 #endif /* !UTILS_FUNCTIONAL_H */
const auto GetY
Lambda function that return the x value of an object.
Definition: Functional.h:95
const auto GetSecond
Lambda function that returns the second element in a pair.
Definition: Functional.h:84
const auto OptHasValue
Lambda function that returns whether a std::optional has value.
Definition: Functional.h:36
const auto IfNotNull
Lambda function that performs a callback on an if it is nor null. Otherwise it ignores it...
Definition: Functional.h:89
const auto StaticCast
StaticCast a value to a different type.
Definition: Functional.h:99
const auto OptValue
Lambda function that gets std::optional&#39;s value.
Definition: Functional.h:30
Contains common lambda functions.
Definition: Functional.h:12
const auto GetSize
Lambda function that returns the size of an object.
Definition: Functional.h:72
const auto IsEmpty
Lambda function that returns whether the object is empty.
Definition: Functional.h:60
const auto GetPtrId
Lambda function that uses &#39;GetId&#39; function to get object&#39;s id.
Definition: Functional.h:24
const auto GetX
Lambda function that return the x value of an object.
Definition: Functional.h:92
const auto Is
Lambda function that casts the object to bool.
Definition: Functional.h:42
const auto IsNullptr
Lambda function that return whether the object is null pointer.
Definition: Functional.h:48
const auto GetFirst
Lambda function that returns the first element in a pair.
Definition: Functional.h:78
const auto IsNotNullptr
Lambda function that return whether the object is not a null pointer.
Definition: Functional.h:54
const auto GetId
Lambda function that uses &#39;GetId&#39; function to get object&#39;s id.
Definition: Functional.h:18
const auto IsNotEmpty
Lambda function that returns whether the object is not empty.
Definition: Functional.h:66