CARLA
 
载入中...
搜索中...
未找到
MoveHandler.h
浏览该文件的文档.
1// Copyright (c) 2019 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 <type_traits> // 包含类型特征相关的头文件,提供类型特性支持
10#include <utility> // 包含通用工具函数,比如 std::move
11
12namespace carla { // 定义命名空间 carla
13namespace detail { // 定义命名空间 detail,用于实现细节
14
15
16 template <typename FunctorT> // 定义一个模板结构体,接受任意类型 FunctorT
17 struct MoveWrapper : FunctorT { // MoveWrapper 继承自 FunctorT
18 MoveWrapper(FunctorT &&f) : FunctorT(std::move(f)) {} // 构造函数,移动构造 FunctorT
19
20 MoveWrapper(MoveWrapper &&) = default; // 移动构造函数,使用默认实现
21 MoveWrapper& operator=(MoveWrapper &&) = default; // 移动赋值运算符,使用默认实现
22
23 MoveWrapper(const MoveWrapper &); // 声明复制构造函数(未定义)
24 MoveWrapper& operator=(const MoveWrapper &); // 声明复制赋值运算符(未定义)
25 };
26
27} // namespace detail
28
29 /// 下面是一种hack,用于绕过Asio库的限制,使其能够接受仅可移动的处理程序。
30 /// 如果Asio试图复制一个仅可移动的处理程序,那么编译时可能不会立即报错
31 ///
32 /// @see https://stackoverflow.com/a/22891509.
33 template <typename FunctorT> // 定义一个模板函数,接受任意类型 FunctorT
34 auto MoveHandler(FunctorT &&func) { // MoveHandler 函数返回一个移动处理器
35 using F = typename std::decay<FunctorT>::type; // 使用 std::decay 处理 FunctorT 的类型
36 return detail::MoveWrapper<F>{std::move(func)}; // 返回一个 MoveWrapper 实例,移动传入的 func
37 }
38
39} // namespace carla
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
auto MoveHandler(FunctorT &&func)
下面是一种hack,用于绕过Asio库的限制,使其能够接受仅可移动的处理程序。 如果Asio试图复制一个仅可移动的处理程序,那么编译时可能不会立即报错
Definition MoveHandler.h:34
MoveWrapper & operator=(const MoveWrapper &)
MoveWrapper(const MoveWrapper &)
MoveWrapper(MoveWrapper &&)=default
MoveWrapper & operator=(MoveWrapper &&)=default