CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
Functional.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include <utility>
10
11
namespace
carla
{
12
13
class
Functional
{
14
public
:
15
16
/// Creates a recursive callable object, where the itself is passed as first
17
/// argument to @a func. Use case: create recursive lambda.
18
template
<
typename
FuncT>
19
static
auto
MakeRecursive
(FuncT &&func) {
20
return
Recursive<FuncT>
(std::forward<FuncT>(func));
21
}
22
23
/// Creates an "overloaded callable object" out of one or more callable
24
/// objects, each callable object will contribute with an overload of
25
/// operator(). Use case: combine several lambdas into a single lambda.
26
template
<
typename
... FuncTs>
27
static
auto
MakeOverload
(FuncTs &&... fs) {
28
return
Overload
<FuncTs...>(std::forward<FuncTs>(fs)...);
29
}
30
31
/// @see MakeRecursive and MakeOverload.
32
template
<
typename
... FuncTs>
33
static
auto
MakeRecursiveOverload
(FuncTs &&... fs) {
34
return
MakeRecursive
(
MakeOverload
(std::forward<FuncTs>(fs)...));
35
}
36
37
private
:
38
39
template
<
typename
... Ts>
40
struct
Overload
;
41
42
template
<
typename
T,
typename
... Ts>
43
struct
Overload
<T, Ts...> : T,
Overload
<Ts...> {
44
Overload
(T &&func, Ts &&... rest)
45
: T(
std
::forward<T>(func)),
46
Overload
<Ts...>(
std
::forward<Ts>(rest)...) {}
47
48
using
T::operator();
49
50
using
Overload
<Ts...>::operator();
51
};
52
53
template
<
typename
T>
54
struct
Overload
<T> : T {
55
Overload
(T &&func) : T(
std
::forward<T>(func)) {}
56
57
using
T::operator();
58
};
59
60
template
<
typename
T>
61
struct
Recursive
{
62
63
explicit
Recursive
(T &&func) :
_func
(
std
::forward<T>(func)) {}
64
65
template
<
typename
... Ts>
66
auto
operator()
(Ts &&... arguments)
const
{
67
return
_func
(*
this
, std::forward<Ts>(arguments)...);
68
}
69
70
private
:
71
72
T
_func
;
73
};
74
75
};
76
77
}
// namespace carla
carla::Functional
Definition
Functional.h:13
carla::Functional::MakeRecursive
static auto MakeRecursive(FuncT &&func)
Creates a recursive callable object, where the itself is passed as first argument to func.
Definition
Functional.h:19
carla::Functional::MakeOverload
static auto MakeOverload(FuncTs &&... fs)
Creates an "overloaded callable object" out of one or more callable objects, each callable object wil...
Definition
Functional.h:27
carla::Functional::MakeRecursiveOverload
static auto MakeRecursiveOverload(FuncTs &&... fs)
Definition
Functional.h:33
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
std
Definition
CarlaRecorderCollision.h:31
carla::Functional::Overload< T, Ts... >::Overload
Overload(T &&func, Ts &&... rest)
Definition
Functional.h:44
carla::Functional::Overload< T >::Overload
Overload(T &&func)
Definition
Functional.h:55
carla::Functional::Overload
Definition
Functional.h:40
carla::Functional::Recursive::Recursive
Recursive(T &&func)
Definition
Functional.h:63
carla::Functional::Recursive::_func
T _func
Definition
Functional.h:72
carla::Functional::Recursive::operator()
auto operator()(Ts &&... arguments) const
Definition
Functional.h:66
Generated by
1.18.0