29 template <
typename Obj,
typename T>
31 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
35 template <
typename Obj,
typename T>
37 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
41 template <
typename Obj,
typename T>
42 static Obj *modify(Obj *obj,
Assign<T> &&asgn) {
43 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
44 *obj = std::move(asgn.value);
48 template <
typename Obj,
typename T>
49 static Obj *modify(Obj *obj,
const Assign<T> &asgn) {
50 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
55 template <
typename Obj,
typename Fn>
56 static decltype(
auto) modify(Obj *obj, Fn fn) {
57 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
61 template <
typename Obj,
typename... Selectors>
62 static Obj *modify(Obj *obj,
Index idx, Selectors &&...selectors) {
63 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
64 BUG_CHECK(obj->size() > idx.value,
"Index %1% out of bounds of %2%", idx.value, obj);
65 modifyRef((*obj)[idx.value], std::forward<Selectors>(selectors)...);
69 template <
typename Obj,
typename To,
typename... Selectors>
71 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
72 auto *casted = cast(obj);
73 BUG_CHECK(casted,
"Cast of %1% failed", obj);
74 return modify(casted, std::forward<Selectors>(selectors)...);
77 template <
typename Obj,
typename T,
typename Sub,
typename... Selectors>
78 static Obj *modify(Obj *obj, Sub T::*member, Selectors &&...selectors) {
79 static_assert(!std::is_const_v<Obj>,
"Cannot modify constant object");
80 modifyRef(obj->*member, std::forward<Selectors>(selectors)...);
84 template <
typename T,
typename... Selectors>
85 static void modifyRef(T &ref, Selectors &&...selectors) {
86 if constexpr (std::is_pointer_v<T>) {
87 ref = modify(ref->clone(), std::forward<Selectors>(selectors)...);
89 auto *res = modify(&ref, std::forward<Selectors>(selectors)...);