38 template <
typename Obj,
typename T>
40 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
44 template <
typename Obj,
typename T>
46 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
50 template <
typename Obj,
typename T>
51 static Obj *modify(Obj *obj,
Assign<T> &&asgn) {
52 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
53 *obj = std::move(asgn.value);
57 template <
typename Obj,
typename T>
58 static Obj *modify(Obj *obj,
const Assign<T> &asgn) {
59 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
64 template <
typename Obj,
typename Fn>
65 static decltype(
auto) modify(Obj *obj, Fn fn) {
66 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
70 template <
typename Obj,
typename... Selectors>
71 static Obj *modify(Obj *obj,
Index idx, Selectors &&...selectors) {
72 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
73 BUG_CHECK(obj->size() > idx.value,
"Index %1% out of bounds of %2%", idx.value, obj);
74 modifyRef((*obj)[idx.value], std::forward<Selectors>(selectors)...);
78 template <
typename Obj,
typename To,
typename... Selectors>
80 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
81 auto *casted = cast(obj);
82 BUG_CHECK(casted,
"Cast of %1% failed", obj);
83 return modify(casted, std::forward<Selectors>(selectors)...);
86 template <
typename Obj,
typename T,
typename Sub,
typename... Selectors>
87 static Obj *modify(Obj *obj, Sub T::*member, Selectors &&...selectors) {
88 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
89 modifyRef(obj->*member, std::forward<Selectors>(selectors)...);
93 template <
typename T,
typename... Selectors>
94 static void modifyRef(T &ref, Selectors &&...selectors) {
95 if constexpr (std::is_pointer_v<T>) {
96 ref = modify(ref->clone(), std::forward<Selectors>(selectors)...);
98 auto *res = modify(&ref, std::forward<Selectors>(selectors)...);