0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 19:58:53 +02:00

ircd::util: Add index() util.

This commit is contained in:
Jason Volk 2018-08-15 22:48:48 -07:00
parent ead6855b3a
commit 69e1c3478f

View file

@ -163,7 +163,33 @@ at(It &&start,
if(!i)
return start;
throw std::out_of_range("at(a, b, i): 'i' out of range");
throw std::out_of_range
{
"at(a, b, i): 'i' out of range"
};
}
/// Like std::find() -> std::distance(), but with out_of_range exception
///
template<class It,
class value>
typename std::enable_if<is_forward_iterator<It>() || is_input_iterator<It>(), size_t>::type
index(const It &start,
const It &stop,
value &&val)
{
const auto it
{
std::find(start, stop, std::forward<value>(val))
};
if(likely(it != stop))
return std::distance(start, it);
throw std::out_of_range
{
"index(a, b, val): 'val' not contained in set"
};
}
//