CARLA
 
载入中...
搜索中...
未找到
Functional.h
浏览该文件的文档.
1// Copyright (c) 2017 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
11namespace 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
73 };
74
75 };
76
77} // namespace carla
static auto MakeRecursive(FuncT &&func)
Creates a recursive callable object, where the itself is passed as first argument to func.
Definition Functional.h:19
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
static auto MakeRecursiveOverload(FuncTs &&... fs)
Definition Functional.h:33
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
Overload(T &&func, Ts &&... rest)
Definition Functional.h:44
auto operator()(Ts &&... arguments) const
Definition Functional.h:66