predicate.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 476 行 · 第 1/2 页

HPP
476
字号
            const Range2T& Test)        {            return contains(Input, Test, is_equal());        }        //! 'Contains' predicate ( case insensitive )        /*!            This predicate holds when the test container is contained in the Input.            Elements are compared case insensitively.            \param Input An input sequence            \param Test A test sequence            \param Loc A locale used for case insensitive comparison            \return The result of the test            \note This function provides the strong exception-safety guarantee        */        template<typename Range1T, typename Range2T>        inline bool icontains(             const Range1T& Input,             const Range2T& Test,             const std::locale& Loc=std::locale())        {            return contains(Input, Test, is_iequal(Loc));        }//  equals predicate  -----------------------------------------------//        //! 'Equals' predicate        /*!            This predicate holds when the test container is equal to the            input container i.e. all elements in both containers are same.            When the optional predicate is specified, it is used for character-wise            comparison.            \param Input An input sequence            \param Test A test sequence            \param Comp An element comparison predicate            \return The result of the test            \note This is a two-way version of \c std::equal algorithm            \note This function provides the strong exception-safety guarantee        */        template<typename Range1T, typename Range2T, typename PredicateT>        inline bool equals(             const Range1T& Input,             const Range2T& Test,            PredicateT Comp)        {            iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(as_literal(Input));            iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(as_literal(Test));            typedef BOOST_STRING_TYPENAME                 range_const_iterator<Range1T>::type Iterator1T;            typedef BOOST_STRING_TYPENAME                 range_const_iterator<Range2T>::type Iterator2T;                            Iterator1T InputEnd=::boost::end(lit_input);            Iterator2T TestEnd=::boost::end(lit_test);            Iterator1T it=::boost::begin(lit_input);            Iterator2T pit=::boost::begin(lit_test);            for(;                it!=InputEnd && pit!=TestEnd;                ++it,++pit)            {                if( !(Comp(*it,*pit)) )                    return false;            }            return  (pit==TestEnd) && (it==InputEnd);        }        //! 'Equals' predicate        /*!            \overload        */        template<typename Range1T, typename Range2T>        inline bool equals(             const Range1T& Input,             const Range2T& Test)        {            return equals(Input, Test, is_equal());        }        //! 'Equals' predicate ( case insensitive )        /*!            This predicate holds when the test container is equal to the            input container i.e. all elements in both containers are same.            Elements are compared case insensitively.            \param Input An input sequence            \param Test A test sequence            \param Loc A locale used for case insensitive comparison            \return The result of the test            \note This is a two-way version of \c std::equal algorithm            \note This function provides the strong exception-safety guarantee        */        template<typename Range1T, typename Range2T>        inline bool iequals(             const Range1T& Input,             const Range2T& Test,            const std::locale& Loc=std::locale())        {            return equals(Input, Test, is_iequal(Loc));        }// lexicographical_compare predicate -----------------------------//        //! Lexicographical compare predicate        /*!             This predicate is an overload of std::lexicographical_compare             for range arguments             It check whether the first argument is lexicographically less             then the second one.             If the optional predicate is specified, it is used for character-wise             comparison             \param Arg1 First argument              \param Arg2 Second argument             \param Pred Comparison predicate             \return The result of the test             \note This function provides the strong exception-safety guarantee         */        template<typename Range1T, typename Range2T, typename PredicateT>        inline bool lexicographical_compare(            const Range1T& Arg1,            const Range2T& Arg2,            PredicateT Pred)        {            iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_arg1(as_literal(Arg1));            iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_arg2(as_literal(Arg2));            return std::lexicographical_compare(                ::boost::begin(lit_arg1),                ::boost::end(lit_arg1),                ::boost::begin(lit_arg2),                ::boost::end(lit_arg2),                Pred);        }        //! Lexicographical compare predicate        /*!            \overload         */        template<typename Range1T, typename Range2T>            inline bool lexicographical_compare(            const Range1T& Arg1,            const Range2T& Arg2)        {            return lexicographical_compare(Arg1, Arg2, is_less());        }        //! Lexicographical compare predicate (case-insensitive)        /*!            This predicate is an overload of std::lexicographical_compare            for range arguments.            It check whether the first argument is lexicographically less            then the second one.            Elements are compared case insensitively             \param Arg1 First argument              \param Arg2 Second argument             \param Loc A locale used for case insensitive comparison             \return The result of the test             \note This function provides the strong exception-safety guarantee         */        template<typename Range1T, typename Range2T>        inline bool ilexicographical_compare(            const Range1T& Arg1,            const Range2T& Arg2,            const std::locale& Loc=std::locale())        {            return lexicographical_compare(Arg1, Arg2, is_iless(Loc));        }        //  all predicate  -----------------------------------------------//        //! 'All' predicate        /*!            This predicate holds it all its elements satisfy a given             condition, represented by the predicate.                        \param Input An input sequence            \param Pred A predicate            \return The result of the test            \note This function provides the strong exception-safety guarantee        */        template<typename RangeT, typename PredicateT>        inline bool all(             const RangeT& Input,             PredicateT Pred)        {            iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_input(as_literal(Input));            typedef BOOST_STRING_TYPENAME                 range_const_iterator<RangeT>::type Iterator1T;            Iterator1T InputEnd=::boost::end(lit_input);            for( Iterator1T It=::boost::begin(lit_input); It!=InputEnd; ++It)            {                if (!Pred(*It))                    return false;            }                        return true;        }    } // namespace algorithm    // pull names to the boost namespace    using algorithm::starts_with;    using algorithm::istarts_with;    using algorithm::ends_with;    using algorithm::iends_with;    using algorithm::contains;    using algorithm::icontains;    using algorithm::equals;    using algorithm::iequals;    using algorithm::all;    using algorithm::lexicographical_compare;    using algorithm::ilexicographical_compare;} // namespace boost#endif  // BOOST_STRING_PREDICATE_HPP

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?