diff options
author | Subv <subv2112@gmail.com> | 2014-06-01 22:43:24 -0500 |
---|---|---|
committer | Subv <subv2112@gmail.com> | 2014-06-01 22:43:24 -0500 |
commit | 18924654a3c052f20988870ca2da25ad857dc86e (patch) | |
tree | 177ffbe9d0ffbc8f384c0caa26052d8d3dad7dae /src/server/shared/Containers.h | |
parent | 48ec2df81fa8f88cd32d7a79b587603aedbd89e0 (diff) | |
parent | 289a5c4318c5509eafeb36389a81bddc2ed349ca (diff) |
Merge branch '4.3.4' of github.com:TrinityCore/TrinityCore into 4.3.4_phases
Diffstat (limited to 'src/server/shared/Containers.h')
-rw-r--r-- | src/server/shared/Containers.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/server/shared/Containers.h b/src/server/shared/Containers.h index d6ba98e4ed4..9121fbe2a97 100644 --- a/src/server/shared/Containers.h +++ b/src/server/shared/Containers.h @@ -64,6 +64,34 @@ namespace Trinity std::advance(it, urand(0, container.size() - 1)); return *it; } + + /** + * @fn bool Trinity::Containers::Intersects(Iterator first1, Iterator last1, Iterator first2, Iterator last2) + * + * @brief Checks if two SORTED containers have a common element + * + * @param first1 Iterator pointing to start of the first container + * @param last1 Iterator pointing to end of the first container + * @param first2 Iterator pointing to start of the second container + * @param last2 Iterator pointing to end of the second container + * + * @return true if containers have a common element, false otherwise. + */ + template<class Iterator1, class Iterator2> + bool Intersects(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) + { + while (first1 != last1 && first2 != last2) + { + if (*first1 < *first2) + ++first1; + else if (*first2 < *first1) + ++first2; + else + return true; + } + + return false; + } } //! namespace Containers } |