@@ -298,6 +298,34 @@ all the value types in the original cursors:
298
298
lager::reader<std::tuple<int, std::string>> dual_ro =
299
299
lager::with(num, str_ro);
300
300
301
+ .. _derive-a-read-write-cursor-from-a-read-only-one :
302
+
303
+ Derive a read-write cursor from a read-only one
304
+ ---------------
305
+
306
+ You can use ``lager::with_setter `` to derive a read-write cursor from a
307
+ read-only cursor.
308
+
309
+ .. code-block :: c++
310
+
311
+ #include <lager/setter.hpp>
312
+
313
+ auto store = lager::make_store<int>(
314
+ 0,
315
+ lager::with_manual_event_loop{},
316
+ lager::with_reducer([](int s, int a) { return a; }));
317
+ auto cursor = lager::with_setter(
318
+ store,
319
+ [&](int x) { store.dispatch(x); });
320
+
321
+ store.dispatch(42);
322
+ std::cout << store.get() << std::endl; // 42
323
+ std::cout << cursor.get() << std::endl; // 42
324
+
325
+ cursor.set(5);
326
+ std::cout << cursor.get() << std::endl; // 5
327
+ std::cout << store.get() << std::endl; // 5
328
+
301
329
.. _using-cursors :
302
330
303
331
Using cursors
@@ -451,15 +479,15 @@ room model and watch it for changes:
451
479
});
452
480
}
453
481
};
454
-
482
+
455
483
.. note :: A ``lager::watch(reader, ...)`` is bound to the
456
484
``reader `` object. It is simply an alias of
457
485
``reader.watch(...) ``. This means that when the reader
458
486
object goes out of scope, the watch is disposed. For
459
487
example:
460
488
461
489
.. code-block :: c++
462
-
490
+
463
491
void setup_watch() {
464
492
auto reader = my_store[&my_model::foo];
465
493
0 commit comments