Containers utils: use Container&& in order to accept temporaries
This commit is contained in:
parent
2f410f62e4
commit
f82a2e22a1
|
@ -137,27 +137,27 @@ struct ReversedContainer
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Container>
|
template<typename Container>
|
||||||
ReversedContainer<Container> reversed(Container& container)
|
ReversedContainer<Container> reversed(Container&& container)
|
||||||
{
|
{
|
||||||
return ReversedContainer<Container>(container);
|
return ReversedContainer<Container>(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Container, typename T>
|
template<typename Container, typename T>
|
||||||
auto find(Container& container, const T& value) -> decltype(container.begin())
|
auto find(Container&& container, const T& value) -> decltype(container.begin())
|
||||||
{
|
{
|
||||||
return std::find(container.begin(), container.end(), value);
|
return std::find(container.begin(), container.end(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container, typename T>
|
template<typename Container, typename T>
|
||||||
auto find_if(Container& container, T op) -> decltype(container.begin())
|
auto find_if(Container&& container, T op) -> decltype(container.begin())
|
||||||
{
|
{
|
||||||
return std::find_if(container.begin(), container.end(), op);
|
return std::find_if(container.begin(), container.end(), op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename Container, typename T>
|
template<typename Container, typename T>
|
||||||
bool contains(const Container& container, const T& value)
|
bool contains(Container&& container, const T& value)
|
||||||
{
|
{
|
||||||
return (not container.empty()) and find(container, value) != container.end();
|
return (not container.empty()) and find(container, value) != container.end();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user