MCPcopy Create free account
hub / github.com/BowenFu/matchit.cpp / Block

Class Block

develop/matchit/patterns.h:798–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

796 {
797 private:
798 class Block
799 {
800 public:
801 ValueVariant<Type> mVariant;
802 int32_t mDepth;
803
804 constexpr auto &variant() { return mVariant; }
805 constexpr auto hasValue() const
806 {
807 return std::visit(overload([](Type const &)
808 { return true; },
809 [](Type const *)
810 { return true; },
811 [](std::monostate const &)
812 { return false; }),
813 mVariant);
814 }
815 constexpr decltype(auto) value() const
816 {
817 return std::visit(
818 overload([](Type const &v) -> Type const & { return v; },
819 [](Type const *p) -> Type const & { return *p; },
820 [](std::monostate const &) -> Type const & {
821 throw std::logic_error("invalid state!");
822 }),
823 mVariant);
824 }
825
826 constexpr decltype(auto) mutableValue()
827 {
828 return std::visit(
829 overload([](Type &v) -> Type & { return v; },
830 [](Type const *) -> Type & {
831 throw std::logic_error(
832 "Cannot get mutableValue for pointer type!");
833 },
834 [](std::monostate &) -> Type & {
835 throw std::logic_error("Invalid state!");
836 }),
837 mVariant);
838 }
839 constexpr void reset(int32_t depth)
840 {
841 if (mDepth - depth >= 0)
842 {
843 mVariant = {};
844 mDepth = depth;
845 }
846 }
847 constexpr void confirm(int32_t depth)
848 {
849 if (mDepth > depth || mDepth == 0)
850 {
851 assert(depth == mDepth - 1 || depth == mDepth || mDepth == 0);
852 mDepth = depth;
853 }
854 }
855 };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected