首页 > 代码库 > stl_container容器和std_algorithm算法相同的函数
stl_container容器和std_algorithm算法相同的函数
八、算法和容器中存在的功能相同的函数:
8.1、array:
8.1.1、fill。
1、在array中:void fill (const value_type& val);
2、在algorithm中:
template <class ForwardIterator, class T>
void fill (ForwardIterator first, ForwardIterator last, const T& val);
8.1.2、swap。
1、在array中:
void swap (array& x);
2、在algorithm中:
template <class T> void swap (T& a, T& b);
8.2、vector:
8.2.1、swap。
1、在vector中:
void swap (vector& x);
2、在algorithm中:
template <class T> void swap (T& a, T& b);
8.3、list:
8.3.1、swap。
1、在list中:
void swap (list& x);
2、在algorithm中:
template <class T> void swap (T& a, T& b);
8.3.2、remove。
1、在list中:
void remove (const value_type& val);
2、在algorithm中:
template <class ForwardIterator, class T>
ForwardIterator remove (ForwardIterator first, ForwardIterator last, const T& val);
8.3.3、remove_if。
1、在list中:
template <class Predicate>
void remove_if (Predicate pred);
2、在algorithm中:
template <class ForwardIterator, class UnaryPredicate>
ForwardIterator remove_if (ForwardIterator first, ForwardIterator last,
UnaryPredicate pred);
8.3.4、unique
1、在list中:
(1)void unique();
(2)template <class BinaryPredicate>
void unique (BinaryPredicate binary_pred);
2、在algorithm中:
(1)template <class ForwardIterator>
ForwardIterator unique (ForwardIterator first, ForwardIterator last);
(2)template <class ForwardIterator, class BinaryPredicate>
ForwardIterator unique (ForwardIterator first, ForwardIterator last,
BinaryPredicate pred);
8.3.5、merge。
1、在list中:
(1)void merge (list& x);
(2)template <class Compare>
void merge (list& x, Compare comp);
2、在algorithm中:
(1)template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator merge (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result);
(2)template <class InputIterator1, class InputIterator2,
class OutputIterator, class Compare>
OutputIterator merge (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result, Compare comp);
8.3.6、sort。
1、在list中:
(1)void sort();
(2)template <class Compare>
void sort (Compare comp);
2、在algorithm中:
(1)template <class RandomAccessIterator>
void sort (RandomAccessIterator first, RandomAccessIterator last);
(2)template <class RandomAccessIterator, class Compare>
void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
8.3.7、reverse。
1、在list中:
void reverse();
2、在algorithm中:
template <class BidirectionalIterator>
void reverse (BidirectionalIterator first, BidirectionalIterator last);
8.4、forward_list:
8.4.1、swap。
1、在forward_list中:
void swap (forward_list& x);
2、在algorithm中:
template <class T> void swap (T& a, T& b);
8.5、deque:
8.5.1、swap。
1、在deque中:
void swap (deque& x);
2、在algorithm中:
template <class T> void swap (T& a, T& b);
8.6、set和map中是一样的:
8.6.1、swap。
1、在set中:
void swap (set& x);
2、在algorithm中:
template <class T> void swap (T& a, T& b);
8.6.2、find。
1、在set中:
iterator find (const value_type& val) const;
2、在algorithm中:
template <class InputIterator, class T>
InputIterator find (InputIterator first, InputIterator last, const T& val);
8.6.3、count。
1、在set中:
size_type count (const value_type& val) const;
2、在algorithm中:
template <class InputIterator, class T>
typename iterator_traits<InputIterator>::difference_type
count (InputIterator first, InputIterator last, const T& val);
8.6.4、lower_bound。
1、在set中:
iterator lower_bound (const value_type& val) const;
2、在algorithm中:
(1)template <class ForwardIterator, class T>
ForwardIterator lower_bound (ForwardIterator first, ForwardIterator last,
const T& val);
(2)template <class ForwardIterator, class T, class Compare>
ForwardIterator lower_bound (ForwardIterator first, ForwardIterator last,
const T& val, Compare comp);
8.6.5、upper_bound。
1、在set中:
iterator upper_bound (const value_type& val) const;
2、在algorithm中:
(1)template <class ForwardIterator, class T>
ForwardIterator upper_bound (ForwardIterator first, ForwardIterator last,
const T& val);
(2)template <class ForwardIterator, class T, class Compare>
ForwardIterator upper_bound (ForwardIterator first, ForwardIterator last,
const T& val, Compare comp);
8.6.6、equal_range。
1、在set中:
pair<iterator,iterator>
equal_range (const value_type& val) const;
2、在algorithm中:
(1)template <class ForwardIterator, class T>
pair<ForwardIterator,ForwardIterator>
equal_range (ForwardIterator first, ForwardIterator last, const T& val);
(2)template <class ForwardIterator, class T, class Compare>
pair<ForwardIterator,ForwardIterator>
equal_range (ForwardIterator first, ForwardIterator last, const T& val,
Compare comp);
stl_container容器和std_algorithm算法相同的函数