CARLA
MoveHandler.h
Go to the documentation of this file.
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>
11 
12 namespace carla {
13 namespace detail {
14 
15  template <typename FunctorT>
16  struct MoveWrapper : FunctorT {
17  MoveWrapper(FunctorT &&f) : FunctorT(std::move(f)) {}
18 
19  MoveWrapper(MoveWrapper &&) = default;
20  MoveWrapper& operator=(MoveWrapper &&) = default;
21 
22  MoveWrapper(const MoveWrapper &);
24  };
25 
26 } // namespace detail
27 
28  /// Hack to trick asio into accepting move-only handlers, if the handler were
29  /// actually copied it would result in a link error.
30  ///
31  /// @see https://stackoverflow.com/a/22891509.
32  template <typename FunctorT>
33  auto MoveHandler(FunctorT &&func) {
34  using F = typename std::decay<FunctorT>::type;
35  return detail::MoveWrapper<F>{std::move(func)};
36  }
37 
38 } // namespace carla
MoveWrapper(FunctorT &&f)
Definition: MoveHandler.h:17
MoveWrapper & operator=(MoveWrapper &&)=default
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
auto MoveHandler(FunctorT &&func)
Hack to trick asio into accepting move-only handlers, if the handler were actually copied it would re...
Definition: MoveHandler.h:33