begins_with.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file begins_with.hpp
  9. * \author Andrey Semashev
  10. * \date 30.03.2008
  11. *
  12. * This header contains a predicate for checking if the provided string begins with a substring.
  13. */
  14. #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_BEGINS_WITH_HPP_INCLUDED_
  15. #define BOOST_LOG_UTILITY_FUNCTIONAL_BEGINS_WITH_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #include <boost/log/detail/header.hpp>
  18. #ifdef BOOST_HAS_PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. namespace boost {
  22. BOOST_LOG_OPEN_NAMESPACE
  23. //! The \c begins_with functor
  24. struct begins_with_fun
  25. {
  26. typedef bool result_type;
  27. template< typename T, typename U >
  28. bool operator() (T const& left, U const& right) const
  29. {
  30. typedef typename T::const_iterator left_iterator;
  31. typedef typename U::const_iterator right_iterator;
  32. left_iterator left_it = left.begin(), left_end = left.end();
  33. right_iterator right_it = right.begin(), right_end = right.end();
  34. for (; left_it != left_end && right_it != right_end; ++left_it, ++right_it)
  35. {
  36. if (*left_it != *right_it)
  37. break;
  38. }
  39. return right_it == right_end;
  40. }
  41. };
  42. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  43. } // namespace boost
  44. #include <boost/log/detail/footer.hpp>
  45. #endif // BOOST_LOG_UTILITY_FUNCTIONAL_BEGINS_WITH_HPP_INCLUDED_