15 #ifndef OPENSCENARIO_INTERPRETER__POINTER_HPP_
16 #define OPENSCENARIO_INTERPRETER__POINTER_HPP_
25 #include <type_traits>
34 template <
typename Bound>
35 struct Binder :
public T,
public Bound
37 template <
typename... Ts>
38 explicit constexpr Binder(Ts &&...
xs) : Bound(std::forward<decltype(
xs)>(
xs)...)
42 virtual ~Binder() =
default;
44 auto type()
const noexcept ->
const std::type_info &
override {
return typeid(Bound); }
62 auto write(std::ostream & os)
const -> std::ostream &
override
69 using std::shared_ptr<T>::shared_ptr;
71 template <
typename U,
typename... Ts>
74 using Binding = Binder<U>;
75 return static_cast<Pointer>(std::make_shared<Binding>(std::forward<decltype(
xs)>(
xs)...));
78 template <
typename U,
typename... Ts>
81 return *
this = bind<U>(std::forward<decltype(
xs)>(
xs)...);
90 "Dereferencing null-pointer. This is likely due to improper implementation");
94 auto type() const -> const
std::type_info & {
return *
this ?
binding().type() :
typeid(
nullptr); }
97 auto is() const ->
bool
99 return type() ==
typeid(U);
102 template <
typename U>
105 return static_cast<bool>(std::dynamic_pointer_cast<U>(*
this));
108 template <
typename U>
109 auto as() const -> U &
111 if (
const auto bound = std::dynamic_pointer_cast<U>(*
this)) {
119 template <
typename... Ts>
122 return binding().evaluate(*
this, std::forward<decltype(
xs)>(
xs)...);
125 template <
typename... Ts>
128 return binding().accomplished(std::forward<decltype(
xs)>(
xs)...);
131 template <
typename... Ts>
134 return binding().description(std::forward<decltype(
xs)>(
xs)...);
138 template <
typename T>
141 return (pointer ? pointer.
binding().write(os) : (os <<
faint <<
"<TODO/>")) <<
reset;
Definition: pointer.hpp:33
decltype(auto) evaluate(Ts &&... xs) const
Definition: pointer.hpp:120
decltype(auto) binding() const
Definition: pointer.hpp:84
auto as() const -> U &
Definition: pointer.hpp:109
static Pointer bind(Ts &&... xs)
Definition: pointer.hpp:72
auto is_also() const
Definition: pointer.hpp:103
auto is() const -> bool
Definition: pointer.hpp:97
decltype(auto) accomplished(Ts &&... xs) const
Definition: pointer.hpp:126
decltype(auto) rebind(Ts &&... xs)
Definition: pointer.hpp:79
auto type() const -> const std::type_info &
Definition: pointer.hpp:94
decltype(auto) description(Ts &&... xs) const
Definition: pointer.hpp:132
auto operator*(const T &a, const U &b)
Definition: operator.hpp:57
auto reset
Definition: escape_sequence.hpp:34
auto faint
Definition: escape_sequence.hpp:36
auto makeTypename(Ts &&... xs)
Definition: demangle.hpp:30
auto operator<<(std::ostream &, const Unspecified &) -> std::ostream &
Definition: object.cpp:21
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: if_has_member_function_accomplished.hpp:26
Definition: if_has_member_function_description.hpp:26
Definition: if_has_member_function_evaluate.hpp:27
Definition: if_has_stream_output_operator.hpp:28