21
21
#include < lager/lenses/at_or.hpp>
22
22
#include < lager/lenses/attr.hpp>
23
23
#include < lager/lenses/optional.hpp>
24
- #include < lager/lenses/variant.hpp>
25
24
#include < lager/lenses/tuple.hpp>
25
+ #include < lager/lenses/variant.hpp>
26
26
27
27
#include < array>
28
28
@@ -423,6 +423,21 @@ TEST_CASE("lenses, bind_opt")
423
423
}
424
424
}
425
425
426
+
427
+ TEST_CASE (" lenses::force_opt with bind_opt" , " [lenses][force_opt][bind_opt]" )
428
+ {
429
+ auto opt_member_lens = attr (&yearday::day) | force_opt;
430
+ auto bound_opt_member = bind_opt (opt_member_lens);
431
+
432
+ CHECK (view (bound_opt_member, std::optional{yearday{1 , 1 }}) ==
433
+ std::optional{1 });
434
+ CHECK (view (bound_opt_member, std::optional<yearday>{}) == std::nullopt);
435
+ CHECK (set (bound_opt_member, std::optional{yearday{1 , 1 }}, 1 )->day == 1 );
436
+ CHECK (set (bound_opt_member, std::optional{yearday{1 , 1 }}, std::optional{1 })
437
+ ->day == 1 );
438
+ CHECK (!set (bound_opt_member, std::optional<yearday>{}, std::nullopt));
439
+ }
440
+
426
441
TEST_CASE (" lenses::zip pair" , " [lenses][zip][pair]" )
427
442
{
428
443
struct foo
@@ -433,9 +448,8 @@ TEST_CASE("lenses::zip pair", "[lenses][zip][pair]")
433
448
std::pair<foo, int > baz{{42 }, 256 };
434
449
auto zipped = zip (attr (&foo::value), lager::identity);
435
450
436
- baz = over (zipped, baz, [](auto x) {
437
- return std::pair{x.second , x.first };
438
- });
451
+ baz =
452
+ over (zipped, baz, [](auto x) { return std::pair{x.second , x.first }; });
439
453
440
454
CHECK (baz.first .value == 256 );
441
455
CHECK (baz.second == 42 );
0 commit comments