![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/include/boost/algorithm/cxx14/ |
Upload File : |
/* Copyright (c) Marshall Clow 2014. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ /// \file is_permutation.hpp /// \brief Is a sequence a permutation of another sequence (four iterator versions) /// \author Marshall Clow #ifndef BOOST_ALGORITHM_IS_PERMUTATION14_HPP #define BOOST_ALGORITHM_IS_PERMUTATION14_HPP #include <utility> // for std::pair #include <functional> // for std::equal_to #include <iterator> #include <boost/algorithm/cxx11/is_permutation.hpp> #include <boost/algorithm/cxx14/mismatch.hpp> namespace boost { namespace algorithm { /// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, /// ForwardIterator2 first2, ForwardIterator2 last2 ) /// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// /// \param first1 The start of the input sequence /// \param last2 One past the end of the input sequence /// \param first2 The start of the second sequence /// \param last1 One past the end of the second sequence /// \note This function is part of the C++2014 standard library. template< class ForwardIterator1, class ForwardIterator2 > bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2 ) { // How should I deal with the idea that ForwardIterator1::value_type // and ForwardIterator2::value_type could be different? Define my own comparison predicate? std::pair<ForwardIterator1, ForwardIterator2> eq = boost::algorithm::mismatch ( first1, last1, first2, last2 ); if ( eq.first == last1 && eq.second == last2) return true; return boost::algorithm::detail::is_permutation_tag ( eq.first, last1, eq.second, last2, std::equal_to<typename std::iterator_traits<ForwardIterator1>::value_type> (), typename std::iterator_traits<ForwardIterator1>::iterator_category (), typename std::iterator_traits<ForwardIterator2>::iterator_category ()); } /// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, /// ForwardIterator2 first2, ForwardIterator2 last2, /// BinaryPredicate p ) /// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// /// \param first1 The start of the input sequence /// \param last1 One past the end of the input sequence /// \param first2 The start of the second sequence /// \param last2 One past the end of the second sequence /// \param pred The predicate to compare elements with /// /// \note This function is part of the C++2014 standard library. template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate > bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred ) { std::pair<ForwardIterator1, ForwardIterator2> eq = boost::algorithm::mismatch ( first1, last1, first2, last2, pred ); if ( eq.first == last1 && eq.second == last2) return true; return boost::algorithm::detail::is_permutation_tag ( first1, last1, first2, last2, pred, typename std::iterator_traits<ForwardIterator1>::iterator_category (), typename std::iterator_traits<ForwardIterator2>::iterator_category ()); } }} #endif // BOOST_ALGORITHM_IS_PERMUTATION14_HPP