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

Class Block

include/matchit.h:1105–1162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1103 {
1104 private:
1105 class Block
1106 {
1107 public:
1108 ValueVariant<Type> mVariant;
1109 int32_t mDepth;
1110
1111 constexpr auto &variant() { return mVariant; }
1112 constexpr auto hasValue() const
1113 {
1114 return std::visit(overload([](Type const &)
1115 { return true; },
1116 [](Type const *)
1117 { return true; },
1118 [](std::monostate const &)
1119 { return false; }),
1120 mVariant);
1121 }
1122 constexpr decltype(auto) value() const
1123 {
1124 return std::visit(
1125 overload([](Type const &v) -> Type const & { return v; },
1126 [](Type const *p) -> Type const & { return *p; },
1127 [](std::monostate const &) -> Type const & {
1128 throw std::logic_error("invalid state!");
1129 }),
1130 mVariant);
1131 }
1132
1133 constexpr decltype(auto) mutableValue()
1134 {
1135 return std::visit(
1136 overload([](Type &v) -> Type & { return v; },
1137 [](Type const *) -> Type & {
1138 throw std::logic_error(
1139 "Cannot get mutableValue for pointer type!");
1140 },
1141 [](std::monostate &) -> Type & {
1142 throw std::logic_error("Invalid state!");
1143 }),
1144 mVariant);
1145 }
1146 constexpr void reset(int32_t depth)
1147 {
1148 if (mDepth - depth >= 0)
1149 {
1150 mVariant = {};
1151 mDepth = depth;
1152 }
1153 }
1154 constexpr void confirm(int32_t depth)
1155 {
1156 if (mDepth > depth || mDepth == 0)
1157 {
1158 assert(depth == mDepth - 1 || depth == mDepth || mDepth == 0);
1159 mDepth = depth;
1160 }
1161 }
1162 };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected