@@ -443,7 +443,7 @@ TEST_CASE("choice and_then", "[choice][and_then]")
443443
444444TEST_CASE (" choice transform" , " [choice][transform]" )
445445{
446- WHEN (" size 1 " )
446+ WHEN (" size 2, only one set " )
447447 {
448448 using type = fn::choice<bool , int >;
449449 constexpr auto init = std::in_place_type<int >;
@@ -503,15 +503,14 @@ TEST_CASE("choice transform", "[choice][transform]")
503503 == fn::choice<double >{5.25 });
504504 }
505505
506- WHEN (" size 4 " )
506+ WHEN (" size 2 " )
507507 {
508- static constexpr auto sizeof_string = sizeof (std::string);
509508 using ::fn::choice;
510509 using ::fn::sum;
511510 constexpr auto fn1 = [](auto i) noexcept -> std::size_t { return sizeof (i); };
512511
513- using type = choice<double , int , std::string, std::string_view >;
514- static_assert (type::size == 4 );
512+ using type = choice<double , int >;
513+ static_assert (type::size == 2 );
515514
516515 WHEN (" element v0 set" )
517516 {
@@ -583,84 +582,5 @@ TEST_CASE("choice transform", "[choice][transform]")
583582 == choice{true });
584583 }
585584 }
586-
587- WHEN (" element v2 set" )
588- {
589- type a{std::in_place_type<std::string>, " bar" };
590- CHECK (a.data .v2 == " bar" );
591- WHEN (" value only" )
592- {
593- // TODO Change single CHECK below to static_assert when supported by Clang
594- CHECK (type{std::in_place_type<std::string>, " bar" }.transform (fn1) == choice{sizeof_string});
595- CHECK (a.transform ( //
596- fn::overload ( //
597- [](auto ) -> sum<bool , std::string> { throw 1 ; },
598- [](std::string &i) -> bool { return i == " bar" ; }, [](std::string const &) -> bool { throw 0 ; },
599- [](std::string &&) -> bool { throw 0 ; }, [](std::string const &&) -> bool { throw 0 ; }))
600- == choice<bool , std::string>{true });
601- CHECK (std::as_const (a).transform ( //
602- fn::overload ( //
603- [](auto ) -> sum<bool , std::string> { throw 1 ; }, [](std::string &) -> bool { throw 0 ; },
604- [](std::string const &i) -> bool { return i == " bar" ; }, [](std::string &&) -> bool { throw 0 ; },
605- [](std::string const &&) -> bool { throw 0 ; }))
606- == choice<bool , std::string>{true });
607- CHECK (type{std::in_place_type<std::string>, " bar" }.transform ( //
608- fn::overload ( //
609- [](auto ) -> sum<bool , std::string> { throw 1 ; }, [](std::string &) -> bool { throw 0 ; },
610- [](std::string const &) -> bool { throw 0 ; }, [](std::string &&i) -> bool { return i == " bar" ; },
611- [](std::string const &&) -> bool { throw 0 ; }))
612- == choice<bool , std::string>{true });
613- CHECK (std::move (std::as_const (a))
614- .transform ( //
615- fn::overload ( //
616- [](auto ) -> sum<bool , std::string> { throw 1 ; }, [](std::string &) -> bool { throw 0 ; },
617- [](std::string const &) -> bool { throw 0 ; }, [](std::string &&) -> bool { throw 0 ; },
618- [](std::string const &&i) -> bool { return i == " bar" ; }))
619- == choice<bool , std::string>{true });
620- }
621- }
622-
623- WHEN (" element v3 set" )
624- {
625- type a{std::in_place_type<std::string_view>, " baz" };
626- CHECK (a.data .v3 == " baz" );
627- WHEN (" value only" )
628- {
629- static_assert (type{std::in_place_type<std::string_view>, " baz" }.transform (fn1) == choice{16uz});
630- CHECK (a.transform ( //
631- fn::overload ( //
632- [](auto ) -> sum<int , std::string_view> { throw 1 ; },
633- [](std::string_view &i) -> sum<bool , int > { return {i == " baz" }; },
634- [](std::string_view const &) -> sum<bool , int > { throw 0 ; },
635- [](std::string_view &&) -> sum<bool , int > { throw 0 ; },
636- [](std::string_view const &&) -> sum<bool , int > { throw 0 ; }))
637- == choice<bool , int , std::string_view>{true });
638- CHECK (std::as_const (a).transform ( //
639- fn::overload ( //
640- [](auto ) -> sum<int , std::string_view> { throw 1 ; },
641- [](std::string_view &) -> sum<bool , int > { throw 0 ; },
642- [](std::string_view const &i) -> sum<bool , int > { return {i == " baz" }; },
643- [](std::string_view &&) -> sum<bool , int > { throw 0 ; },
644- [](std::string_view const &&) -> sum<bool , int > { throw 0 ; }))
645- == choice<bool , int , std::string_view>{true });
646- CHECK (type{std::in_place_type<std::string_view>, " baz" }.transform ( //
647- fn::overload ( //
648- [](auto ) -> sum<int , std::string_view> { throw 1 ; },
649- [](std::string_view &) -> sum<bool , int > { throw 0 ; },
650- [](std::string_view const &) -> sum<bool , int > { throw 0 ; },
651- [](std::string_view &&i) -> sum<bool , int > { return {i == " baz" }; },
652- [](std::string_view const &&) -> sum<bool , int > { throw 0 ; }))
653- == choice<bool , int , std::string_view>{true });
654- CHECK (std::move (std::as_const (a))
655- .transform ( //
656- fn::overload ( //
657- [](auto ) -> sum<int , std::string_view> { throw 1 ; },
658- [](std::string_view &) -> sum<bool , int > { throw 0 ; },
659- [](std::string_view const &) -> sum<bool , int > { throw 0 ; },
660- [](std::string_view &&) -> sum<bool , int > { throw 0 ; },
661- [](std::string_view const &&i) -> sum<bool , int > { return {i == " baz" }; }))
662- == choice<bool , int , std::string_view>{true });
663- }
664- }
665585 }
666586}
0 commit comments