Detecting if an element is found inside a container I just wrote this template to detect if a given element is found inside a container:

template &lt;typename Iterator&gt; bool is_contained(Iterator begin, Iterator end, decltype(*begin) object)
{
    for (; begin != end; ++begin)
    {
        if (*begin == object)
        {
            return true;
        }
    }
    return false;
}


Which then would be called for examples as:

bool test = is_contained&lt;decltype(container.begin())&gt;(container.begin(), container.end(), anything);


This works fine, but I believe it is not so readable. I am also new to using decltype which makes me wonder if this would crash, and somehow I wont be calling the template correctly. Any feedback is highly appreciated.
Note that for functions the compiler will detect the template types based on the parameters.
So you can simply write:

bool test = is_contained(container.begin(), container.end(), anything);


I don't particularly like the use of decltype in your function. I would simply make it another template parameter.

template &lt;typename Iterator, typename Value&gt;
bool is_contained(Iterator begin, Iterator end, Value const&amp; object);


Because of the compiler deducing the names you can use any type. Also this is more flexable as it allows you to use any type that is comparable to the type inside the container (rather than only allowing values that are the same type (or trivial convertible)).