简体   繁体   中英

Define Iterator type of template argument

In function below, how to tell the compiler that Iterator is the iterator of Cont ?

template<typename Cont, typename Pred>
Iterator<Cont> find_if(const Cont &c, Pred p)
{
    return std::find_if(std::begin(c), std::end(c), p);
}
template<typename Cont, typename Pred>
auto find_if(const Cont &c, Pred p)
-> decltype(std::begin(c)) // HERE
{
    return std::find_if(std::begin(c), std::end(c), p);
}

Or since version C++14:

template<typename Cont, typename Pred>
auto find_if(const Cont &c, Pred p) //All you need is auto
{
    return std::find_if(std::begin(c), std::end(c), p);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM