scenario_simulator_v2 C++ API
fold.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 SCENARIO_SIMULATOR_EXCEPTION__FOLD_HPP_
16 #define SCENARIO_SIMULATOR_EXCEPTION__FOLD_HPP_
17 
18 #include <functional>
19 #include <utility>
20 
21 namespace common
22 {
23 inline namespace scenario_simulator_exception
24 {
25 template <typename F, typename T>
26 constexpr decltype(auto) fold_left(F &&, T && x)
27 {
28  return std::forward<decltype(x)>(x);
29 }
30 
31 template <typename F, typename T, typename U, typename... Ts>
32 constexpr decltype(auto) fold_left(F && f, T && x, U && y, Ts &&... xs)
33 {
34  return fold_left(
35  f, //
36  f(std::forward<decltype(x)>(x), //
37  std::forward<decltype(y)>(y)), //
38  std::forward<decltype(xs)>(xs)...);
39 }
40 
41 template <typename F, typename T>
42 constexpr decltype(auto) fold_right(F &&, T && x)
43 {
44  return std::forward<decltype(x)>(x);
45 }
46 
47 template <typename F, typename T, typename... Ts>
48 constexpr decltype(auto) fold_right(F && f, T && x, Ts &&... xs)
49 {
50  return f(std::forward<decltype(x)>(x), fold_right(f, std::forward<decltype(xs)>(xs)...));
51 }
52 } // namespace scenario_simulator_exception
53 } // namespace common
54 
55 #endif // OPENSCENARIO_INTERPRETER__FOLD_HPP_
constexpr decltype(auto) fold_left(F &&, T &&x)
Definition: fold.hpp:26
constexpr decltype(auto) fold_right(F &&, T &&x)
Definition: fold.hpp:42
Definition: concatenate.hpp:24
Definition: junit5.hpp:25