Skip to content

Commit

Permalink
Merge pull request #209 from tusooa/tusooa/with-setter-doc
Browse files Browse the repository at this point in the history
Add lager::with_setter doc
  • Loading branch information
arximboldi authored Sep 16, 2024
2 parents 2ef43de + 9ea903d commit 42f874e
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions doc/cursors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,34 @@ all the value types in the original cursors:
lager::reader<std::tuple<int, std::string>> dual_ro =
lager::with(num, str_ro);

.. _derive-a-read-write-cursor-from-a-read-only-one:

Derive a read-write cursor from a read-only one
---------------

You can use ``lager::with_setter`` to derive a read-write cursor from a
read-only cursor.

.. code-block:: c++

#include <lager/setter.hpp>

auto store = lager::make_store<int>(
0,
lager::with_manual_event_loop{},
lager::with_reducer([](int s, int a) { return a; }));
auto cursor = lager::with_setter(
store,
[&](int x) { store.dispatch(x); });

store.dispatch(42);
std::cout << store.get() << std::endl; // 42
std::cout << cursor.get() << std::endl; // 42

cursor.set(5);
std::cout << cursor.get() << std::endl; // 5
std::cout << store.get() << std::endl; // 5

.. _using-cursors:

Using cursors
Expand Down Expand Up @@ -451,15 +479,15 @@ room model and watch it for changes:
});
}
};
.. note:: A ``lager::watch(reader, ...)`` is bound to the
``reader`` object. It is simply an alias of
``reader.watch(...)``. This means that when the reader
object goes out of scope, the watch is disposed. For
example:

.. code-block:: c++

void setup_watch() {
auto reader = my_store[&my_model::foo];

Expand Down

0 comments on commit 42f874e

Please sign in to comment.