C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- std::execution::sequenced_policy, std::execution::parallel_policy, std::execution::parallel_unsequenced_policy, std::execution::unsequenced_policy
- æå¶çº¦ç®æ³ (C++20 èµ·)
- std::is_execution_policy
- std::execution::seq, std::execution::par, std::execution::par_unseq, std::execution::unseq
- std::all_of, std::any_of, std::none_of
- std::for_each_n
- std::sort
- std::reduce
- std::inclusive_scan
- std::exclusive_scan
- std::random_shuffle, std::shuffle
- std::clamp
- std::equal
- std::is_permutation
- std::mismatch
- std::swap
- std::search
- std::transform
- std::for_each
- std::make_heap
- std::count, std::count_if
- std::adjacent_find
- std::find, std::find_if, std::find_if_not
- std::find_end
- std::find_first_of
- std::search_n
- std::lexicographical_compare
- std::lexicographical_compare_three_way
- std::copy, std::copy_if
- std::copy_n
- std::copy_backward
- std::move
- std::move_backward
- std::shift_left, std::shift_right
- std::fill
- std::fill_n
- std::generate
- std::generate_n
- std::iter_swap
- std::swap_ranges
- std::sample
- std::remove, std::remove_if
- std::replace, std::replace_if
- std::reverse
- std::rotate
- std::unique
- std::remove_copy, std::remove_copy_if
- std::replace_copy, std::replace_copy_if
- std::reverse_copy
- std::rotate_copy
- std::unique_copy
- std::is_partitioned
- std::partition_point
- std::partition
- std::partition_copy
- std::stable_partition
- std::is_sorted
- std::is_sorted_until
- std::stable_sort
- std::partial_sort
- std::partial_sort_copy
- std::nth_element
- std::lower_bound
- std::upper_bound
- std::binary_search
- std::equal_range
- std::merge
- std::inplace_merge
- std::set_difference
- std::set_intersection
- std::set_symmetric_difference
- std::set_union
- std::includes
- std::is_heap
- std::is_heap_until
- std::sort_heap
- std::push_heap
- std::pop_heap
- std::max
- std::max_element
- std::min
- std::min_element
- std::minmax
- std::minmax_element
- std::next_permutation
- std::prev_permutation
- std::iota
- std::inner_product
- std::adjacent_difference
- std::accumulate
- std::transform_reduce
- std::partial_sum
- std::transform_inclusive_scan
- std::transform_exclusive_scan
- std::qsort
- std::bsearch
- 注é
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >ç®æ³åº > std::mismatch
std::mismatch
std::pair<InputIt1,InputIt2>
  mismatch( InputIt1 first1, InputIt1 last1,
constexpr std::pair<InputIt1,InputIt2>
       mismatch( InputIt1 first1, InputIt1 last1,
std::pair<ForwardIt1,ForwardIt2>
  mismatch( ExecutionPolicy&& policy, ForwardIt1 first1, ForwardIt1 last1,
std::pair<InputIt1,InputIt2>
  mismatch( InputIt1 first1, InputIt1 last1,
       InputIt2 first2,
constexpr std::pair<InputIt1,InputIt2>
       mismatch( InputIt1 first1, InputIt1 last1,
            InputIt2 first2,
std::pair<ForwardIt1,ForwardIt2>
  mismatch( ExecutionPolicy&& policy, ForwardIt1 first1, ForwardIt1 last1,
       ForwardIt2 first2,
std::pair<InputIt1,InputIt2>
  mismatch( InputIt1 first1, InputIt1 last1,
(C++20 å)
constexpr std::pair<InputIt1,InputIt2>
       mismatch( InputIt1 first1, InputIt1 last1,
std::pair<ForwardIt1,ForwardIt2>
  mismatch( ExecutionPolicy&& policy, ForwardIt1 first1, ForwardIt1 last1,
std::pair<InputIt1,InputIt2>
  mismatch( InputIt1 first1, InputIt1 last1,
       InputIt2 first2, InputIt2 last2,
(C++20 å)
constexpr std::pair<InputIt1,InputIt2>
       mismatch( InputIt1 first1, InputIt1 last1,
            InputIt2 first2, InputIt2 last2,
std::pair<ForwardIt1,ForwardIt2>
  mismatch( ExecutionPolicy&& policy, ForwardIt1 first1, ForwardIt1 last1,
       ForwardIt2 first2, ForwardIt2 last2,
è¿åæ¥èªäºä¸ªèå´ï¼ä¸ä¸ªä»¥ [first1, last1) å®ä¹èå¦ä¸ä¸ªä»¥ [first2,last2) å®ä¹ï¼çé¦ä¸ªä¸å¹é
对ãè¥ä¸æä¾ last2 ï¼éè½½ (1-4) ï¼ï¼å宿代 first2 + (last1 - first1) ã
operator== æ¯è¾å
ç´ ãp æ¯è¾å
ç´ ãpolicy æ§è¡ãè¿äºéè½½ä»
è¥ std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> 为 true æåä¸éè½½å³è®®ãåæ°
| first1, last1 | - | 第ä¸å ç´ èå´ |
| first2, last2 | - | 第äºå ç´ èå´ |
| policy | - | æç¨çæ§è¡çç¥ãç»èè§æ§è¡çç¥ã |
| p | - | è¥å
ç´ åºè¢«å½åç¸çåè¿å âtrue çäºå
è°è¯ã è°è¯å½æ°çç¾ååºçä»·äºå¦ä¸ï¼  bool pred(const Type1 &a, const Type2 &b); è½ç¶ç¾åä¸å¿
æ const & ï¼å½æ°ä¹ä¸è½ä¿®æ¹ä¼ éç»å®ç对象ï¼èä¸å¿
é¡»æ¥åï¼å¯ä¸º const çï¼ç±»å |
| ç±»åè¦æ± | ||
-InputIt1 å¿
须满足éçè¾å
¥è¿ä»£å¨ (LegacyInputIterator) çè¦æ±ã
| ||
-InputIt2 å¿
须满足éçè¾å
¥è¿ä»£å¨ (LegacyInputIterator) çè¦æ±ã
| ||
-ForwardIt1 å¿
须满足éçååè¿ä»£å¨ (LegacyForwardIterator) çè¦æ±ã
| ||
-ForwardIt2 å¿
须满足éçååè¿ä»£å¨ (LegacyForwardIterator) çè¦æ±ã
| ||
-BinaryPredicate å¿
须满足äºå
è°è¯ (BinaryPredicate) çè¦æ±ã
| ||
è¿åå¼
带æåé¦äºä¸ªä¸ç¸çå ç´ çè¿ä»£å¨ç std::pair ã
|
è¥æ¯è¾æµè¾¾ |
(C++14 å) |
|
è¥æ¯è¾æµè¾¾ |
(C++14 èµ·) |
å¤æåº¦
last1 - first1 次åºç¨ operator== æè°è¯ p ãlast1 - first1, last2 - first2) 次åºç¨ operator== æè°è¯ p ãå¼å¸¸
æ¥æå为 ExecutionPolicy çæ¨¡æ¿å½¢åçéè½½æä¸åæ¹å¼æ¥åé误ï¼
- è¥ä½ä¸ºç®æ³ä¸é¨åè°ç¨ç彿°çæ§è¡æåºå¼å¸¸ï¼ä¸
ExecutionPolicy为æ åçç¥ä¹ä¸ï¼åè°ç¨ std::terminate ã对äºä»»ä½å ¶ä»ExecutionPolicyï¼è¡ä¸ºæ¯å®ç°å®ä¹çã - è¥ç®æ³æ æ³åé å åï¼åæåº std::bad_alloc ã
å¯è½çå®ç°
| çæ¬ä¸ |
|---|
template<class InputIt1, class InputIt2> std::pair<InputIt1, InputIt2> mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2) { while (first1 != last1 && *first1 == *first2) { ++first1, ++first2; } return std::make_pair(first1, first2); } |
| çæ¬äº |
template<class InputIt1, class InputIt2, class BinaryPredicate> std::pair<InputIt1, InputIt2> mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p) { while (first1 != last1 && p(*first1, *first2)) { ++first1, ++first2; } return std::make_pair(first1, first2); } |
| çæ¬ä¸ |
template<class InputIt1, class InputIt2> std::pair<InputIt1, InputIt2> mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) { while (first1 != last1 && first2 != last2 && *first1 == *first2) { ++first1, ++first2; } return std::make_pair(first1, first2); } |
| çæ¬å |
template<class InputIt1, class InputIt2, class BinaryPredicate> std::pair<InputIt1, InputIt2> mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate p) { while (first1 != last1 && first2 != last2 && p(*first1, *first2)) { ++first1, ++first2; } return std::make_pair(first1, first2); } |
示ä¾
æ¤ç¨åºç¡®å®åæ¶å¨ç»å®å符串起å§ä¸å¨å ¶ç»å°¾æéåºåæ¶æ¾å°çæé¿å串ï¼å¯è½éå ï¼ã
#include <iostream> #include <string> #include <algorithm> Â std::string mirror_ends(const std::string& in) { return std::string(in.begin(), std::mismatch(in.begin(), in.end(), in.rbegin()).first); } Â int main() { std::cout << mirror_ends("abXYZba") << '\n' << mirror_ends("abca") << '\n' << mirror_ends("aba") << '\n'; }
è¾åºï¼
ab a aba
åé
| ç¡®å®ä¸¤ä¸ªå
ç´ é忝妿¯ç¸åç (彿°æ¨¡æ¿) | |
| (C++11) |
寻æ¾é¦ä¸ªæ»¡è¶³ç¹å®å¤å«æ åçå
ç´ (彿°æ¨¡æ¿) |
| å½ä¸ä¸ªèå´æåå
¸é¡ºåºå°äºå¦ä¸ä¸ªèå´æ¶ï¼è¿å true (彿°æ¨¡æ¿) | |
| æç´¢ä¸ä¸ªå
ç´ èå´ (彿°æ¨¡æ¿) |