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)
8 * \file begins_with.hpp
9 * \author Andrey Semashev
12 * This header contains a predicate for checking if the provided string begins with a substring.
15 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_BEGINS_WITH_HPP_INCLUDED_
16 #define BOOST_LOG_UTILITY_FUNCTIONAL_BEGINS_WITH_HPP_INCLUDED_
18 #include <boost/log/detail/config.hpp>
19 #include <boost/log/detail/header.hpp>
21 #ifdef BOOST_HAS_PRAGMA_ONCE
27 BOOST_LOG_OPEN_NAMESPACE
29 //! The \c begins_with functor
30 struct begins_with_fun
32 typedef bool result_type;
34 template< typename T, typename U >
35 bool operator() (T const& left, U const& right) const
37 typedef typename T::const_iterator left_iterator;
38 typedef typename U::const_iterator right_iterator;
40 left_iterator left_it = left.begin(), left_end = left.end();
41 right_iterator right_it = right.begin(), right_end = right.end();
42 for (; left_it != left_end && right_it != right_end; ++left_it, ++right_it)
44 if (*left_it != *right_it)
47 return right_it == right_end;
51 BOOST_LOG_CLOSE_NAMESPACE // namespace log
55 #include <boost/log/detail/footer.hpp>
57 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_BEGINS_WITH_HPP_INCLUDED_