scenario_simulator_v2 C++ API
print.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef OPENSCENARIO_INTERPRETER__UTILITY__PRINT_HPP_
16 #define OPENSCENARIO_INTERPRETER__UTILITY__PRINT_HPP_
17 
18 #include <iomanip>
19 #include <iostream>
22 #include <type_traits>
23 
25 {
26 inline namespace utility
27 {
28 template <typename T>
29 auto print_to(std::ostream & os, const T & value)
30  -> std::enable_if_t<concepts::HasStreamOutputOperator<T>::value, std::ostream &>
31 {
32  return os << value;
33 }
34 
35 template <typename T>
36 auto print_to(std::ostream & os, const T & iterable) -> std::enable_if_t<
37  not concepts::HasStreamOutputOperator<T>::value and type_traits::Iterable<T>::value,
38  std::ostream &>
39 {
40  os << "[";
41  const auto * separator = "";
42  for (const auto & value : iterable) {
43  os << std::exchange(separator, ", ");
44  print_to(os, value);
45  }
46  return os << "]";
47 }
48 
49 inline auto print_keys_to = [](auto & os, const auto & xs) -> decltype(auto) {
50  if (not xs.empty()) {
51  for (auto iter = std::begin(xs); iter != std::end(xs); ++iter) {
52  os << std::get<0>(*iter);
53  switch (std::distance(iter, std::end(xs))) {
54  case 1:
55  return os;
56  case 2:
57  os << " and ";
58  break;
59  default:
60  os << ", ";
61  break;
62  }
63  }
64  }
65  return os;
66 };
67 } // namespace utility
68 } // namespace openscenario_interpreter
69 
70 #endif // OPENSCENARIO_INTERPRETER__UTILITY__PRINT_HPP_
auto print_to(std::ostream &os, const T &value) -> std::enable_if_t< concepts::HasStreamOutputOperator< T >::value, std::ostream & >
Definition: print.hpp:29
auto print_keys_to
Definition: print.hpp:49
Definition: hypot.hpp:22
auto distance(const geometry_msgs::Pose &pose1, const geometry_msgs::Pose &pose2)
Definition: detection_sensor.cpp:36
Definition: junit5.hpp:25