0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01: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"
};
}
//