0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd: Use util::boolean for globular suite; apply noexcept; minor simplify.

This commit is contained in:
Jason Volk 2020-03-19 11:25:58 -07:00
parent 70e32d9292
commit 71d6bd66c1
2 changed files with 16 additions and 42 deletions

View file

@ -22,25 +22,17 @@ namespace ircd
/// and '?' characters and equality of the string expressions will be
/// determined.
struct ircd::globular_equals
:boolean
{
using is_transparent = std::true_type;
bool s;
operator const bool &() const
{
return s;
}
bool operator()(const string_view &a, const string_view &b) const;
bool operator()(const string_view &a, const string_view &b) const noexcept;
template<class A,
class B>
globular_equals(A&& a, B&& b)
:s{operator()(std::forward<A>(a), std::forward<B>(b))}
:boolean{operator()(std::forward<A>(a), std::forward<B>(b))}
{}
globular_equals() = default;
};
/// Globular match. Similar to globular_equals but only one side of the
@ -51,24 +43,19 @@ struct ircd::globular_equals
struct ircd::globular_match
{
string_view expr;
bool s;
operator const bool &() const
{
return s;
}
bool operator()(const string_view &a) const;
globular_match(const string_view &expr)
:expr{expr}
{}
template<class A>
globular_match(const string_view &expr, A&& a)
:expr{expr}
,s{operator()(std::forward<A>(a))}
{}
bool operator()(A&& a) const noexcept
{
const globular_equals globular_equals
{
expr, std::forward<A>(a)
};
globular_match() = default;
return bool(globular_equals);
}
globular_match(const string_view &expr = {})
:expr{expr}
{}
};

View file

@ -14,7 +14,7 @@
bool
ircd::globular_equals::operator()(const string_view &a, const string_view &b)
const
const noexcept
{
size_t ap(0), bp(0);
while(ap < a.size() && bp < b.size())
@ -53,16 +53,3 @@ const
return iequals(a.substr(ap), b.substr(bp));
}
//
// globular_match
//
bool
ircd::globular_match::operator()(const string_view &a)
const
{
//TODO: optimize.
const globular_equals globular_equals(expr, a);
return bool(globular_equals);
}