Containers utils: use Container&& in order to accept temporaries

This commit is contained in:
Maxime Coste 2013-02-27 19:58:07 +01:00
parent 2f410f62e4
commit f82a2e22a1

View File

@ -137,27 +137,27 @@ struct ReversedContainer
};
template<typename Container>
ReversedContainer<Container> reversed(Container& container)
ReversedContainer<Container> reversed(Container&& container)
{
return ReversedContainer<Container>(container);
}
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);
}
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);
}
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();
}