Skip to content

Commit

Permalink
Code for 'contains', so that it also works for map, unordered_map
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitanand001 committed Aug 29, 2018
1 parent 3cfb64a commit d6878ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions underscore.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "underscore.hpp"
#include <cstddef>
#include <algorithm>
namespace underscore{


Expand Down Expand Up @@ -154,7 +155,29 @@ bool contains(Iterator begin, Iterator end, Data data)
return true;
begin++;
}

return false;

}


template <typename Iterator, typename Data, typename X, typename Y>
bool contains(Iterator begin, Iterator end, std::pair<X, Y> p)
{

while(begin != end)
{

if((*begin).first == p.first and (*begin).second == p.second)
return true;
begin++;
}

return false;

}




}
2 changes: 2 additions & 0 deletions underscore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ int count_by(Iterator begin, Iterator end, Predicate predicate);
template <typename Iterator, typename Data>
bool contains(Iterator begin, Iterator end, Data data);

template <typename Iterator, typename Data, typename X, typename Y>
bool contains(Iterator begin, Iterator end, std::pair<X, Y> p);

0 comments on commit d6878ef

Please sign in to comment.