0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd::util: Add iterator pair type.

This commit is contained in:
Jason Volk 2017-04-02 20:18:54 -07:00
parent a8e6f4fb0a
commit 0a1bf7f47f

View file

@ -729,5 +729,64 @@ struct va_rtti
static_assert(sizeof(va_rtti) == 192 + 8, "");
//
// To collapse pairs of iterators down to a single type
//
template<class T>
struct iterators
:std::pair<typename T::iterator, typename T::iterator>
{
using std::pair<typename T::iterator, typename T::iterator>::pair;
iterators(T &t)
:std::pair<typename T::iterator, typename T::iterator>
{
std::begin(t), std::end(t)
}{}
};
template<class T>
struct const_iterators
:std::pair<typename T::const_iterator, typename T::const_iterator>
{
using std::pair<typename T::const_iterator, typename T::const_iterator>::pair;
const_iterators(const T &t)
:std::pair<typename T::const_iterator, typename T::const_iterator>
{
std::begin(t), std::end(t)
}{}
};
template<class T>
typename T::iterator
begin(const iterators<T> &i)
{
return i.first;
}
template<class T>
typename T::iterator
end(const iterators<T> &i)
{
return i.second;
}
template<class T>
typename T::const_iterator
begin(const const_iterators<T> &ci)
{
return ci.first;
}
template<class T>
typename T::const_iterator
end(const const_iterators<T> &ci)
{
return ci.second;
}
} // namespace util
} // namespace ircd