MCPcopy Create free account
hub / github.com/arximboldi/immer / main

Function main

example/array/array.cpp:13–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <cassert>
12
13int main()
14{
15 {
16 // include:push-back/start
17 auto v1 = immer::array<int>{1};
18 auto v2 = v1.push_back(8);
19
20 assert((v1 == immer::array<int>{1}));
21 assert((v2 == immer::array<int>{1, 8}));
22 // include:push-back/end
23 }
24
25 {
26 // include:set/start
27 auto v1 = immer::array<int>{1, 2, 3};
28 auto v2 = v1.set(0, 5);
29
30 assert((v1 == immer::array<int>{1, 2, 3}));
31 assert((v2 == immer::array<int>{5, 2, 3}));
32 // include:set/end
33 }
34
35 {
36 // include:update/start
37 auto v1 = immer::array<int>{1, 2, 3, 4};
38 auto v2 = v1.update(2, [&](auto l) { return ++l; });
39
40 assert((v1 == immer::array<int>{1, 2, 3, 4}));
41 assert((v2 == immer::array<int>{1, 2, 4, 4}));
42 // include:update/end
43 }
44
45 {
46 // include:take/start
47 auto v1 = immer::array<int>{1, 2, 3, 4, 5, 6};
48 auto v2 = v1.take(3);
49
50 assert((v1 == immer::array<int>{1, 2, 3, 4, 5, 6}));
51 assert((v2 == immer::array<int>{1, 2, 3}));
52 // include:take/end
53 }
54}

Callers

nothing calls this directly

Calls 4

push_backMethod · 0.45
setMethod · 0.45
updateMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected