Skip to content

Commit 42f874e

Browse files
authored
Merge pull request #209 from tusooa/tusooa/with-setter-doc
Add lager::with_setter doc
2 parents 2ef43de + 9ea903d commit 42f874e

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

doc/cursors.rst

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,34 @@ all the value types in the original cursors:
298298
lager::reader<std::tuple<int, std::string>> dual_ro =
299299
lager::with(num, str_ro);
300300

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+
301329
.. _using-cursors:
302330

303331
Using cursors
@@ -451,15 +479,15 @@ room model and watch it for changes:
451479
});
452480
}
453481
};
454-
482+
455483
.. note:: A ``lager::watch(reader, ...)`` is bound to the
456484
``reader`` object. It is simply an alias of
457485
``reader.watch(...)``. This means that when the reader
458486
object goes out of scope, the watch is disposed. For
459487
example:
460488

461489
.. code-block:: c++
462-
490+
463491
void setup_watch() {
464492
auto reader = my_store[&my_model::foo];
465493

0 commit comments

Comments
 (0)