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 limit_;
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}
{}
};
class restore_recursion_depth;
public:
recursion_limiter(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}
{
}
restore_recursion_depth
count()
inline
recursion_limiter::restore_recursion_depth
recursion_limiter::count()
{
++depth_;
if (depth_ > limit_)
@ -3749,7 +3769,6 @@ public:
std::to_string(limit_) + " exceeded");
return restore_recursion_depth{this};
}
};
} // unnamed namespace