Clean up restore_recursion_depth code.

This commit is contained in:
Howard Hinnant 2024-05-10 16:21:36 -04:00
parent 8f8336f42b
commit 6b1c1b8b3a

View File

@ -3718,30 +3718,50 @@ class recursion_limiter
unsigned depth_ = 0; unsigned depth_ = 0;
unsigned limit_; unsigned limit_;
class restore_recursion_depth class restore_recursion_depth;
{
recursion_limiter* rc_;
public:
~restore_recursion_depth() {--(rc_->depth_);}
restore_recursion_depth(restore_recursion_depth&&) = default;
explicit restore_recursion_depth(recursion_limiter* rc) noexcept
: rc_{rc}
{}
};
public: public:
recursion_limiter(recursion_limiter const&) = delete; recursion_limiter(recursion_limiter const&) = delete;
recursion_limiter& operator=(recursion_limiter const&) = delete; recursion_limiter& operator=(recursion_limiter const&) = delete;
explicit recursion_limiter(unsigned limit) noexcept explicit constexpr recursion_limiter(unsigned limit) noexcept;
restore_recursion_depth count();
};
class recursion_limiter::restore_recursion_depth
{
recursion_limiter* rc_;
public:
~restore_recursion_depth();
restore_recursion_depth(restore_recursion_depth&&) = default;
explicit restore_recursion_depth(recursion_limiter* rc) noexcept;
};
inline
recursion_limiter::restore_recursion_depth::~restore_recursion_depth()
{
--(rc_->depth_);
}
inline
recursion_limiter::restore_recursion_depth::restore_recursion_depth(recursion_limiter* rc)
noexcept
: rc_{rc}
{}
inline
constexpr
recursion_limiter::recursion_limiter(unsigned limit) noexcept
: limit_{limit} : limit_{limit}
{ {
} }
restore_recursion_depth inline
count() recursion_limiter::restore_recursion_depth
recursion_limiter::count()
{ {
++depth_; ++depth_;
if (depth_ > limit_) if (depth_ > limit_)
@ -3749,7 +3769,6 @@ public:
std::to_string(limit_) + " exceeded"); std::to_string(limit_) + " exceeded");
return restore_recursion_depth{this}; return restore_recursion_depth{this};
} }
};
} // unnamed namespace } // unnamed namespace