Am 4 May 2016 10:21:21 GMT
schrieb
r...@zedat.fu-berlin.de (Stefan Ram):
> Ralf Goertz <m...@myprovider.invalid> writes:
> >#include <algorithm>
> >#include <vector>
> >template <class C> typename C::iterator find (const C &c, const
> >typename C::value_type & val) {
> > return std::find(c.begin(),c.end(),val);
> >}
> >int main() {
> > std::vector<int> v({47,11});
> > auto it=find(v,47);
> >}
>
> I did not bother to really understand the error message,
> and I don't know whether it's the following that you want,
> but this compiles here (-std=c++17):
<snip>
> #include <utility>
>
> template< typename T >
> typename T::iterator find
> ( T & c,
> typename T::value_type const & val )
> { return ::std::find( begin( c ), end( c ), val ); }
Okay, thanks. This does the trick even with "const T & c". But why don't
we need namespace qualifier std:: in front of "begin" and "end"?
According to
http://www.cplusplus.com/reference/iterator/begin/ that's
where these functions live. And what do you need <utility> for. Here it
works without it (std=c++11)