STL源码剖析之算法:iter_swap & swap

  
  
  
  
  1. template <class ForwardIterator1, class ForwardIterator2, class T>                
  2. inline void __iter_swap(ForwardIterator1 a, ForwardIterator2 b, T*) {             
  3.     T tmp = *a;                                                                   
  4.     *a = *b;                                                                      
  5.     *b = tmp;                                                                     
  6. }                                                                                 
  7.                                                                                   
  8. template <class ForwardIterator1, class ForwardIterator2>                         
  9. inline void iter_swap(ForwardIterator1 a, ForwardIterator2 b) {                   
  10.     __iter_swap(a, b, value_type(a));                                             
  11. }
  
  
  
  
  1. template <class T>  
  2. inline void swap(T &a, T &b) {  
  3.     T tmp = a;  
  4.     a = b;  
  5.     b = tmp;  
  6. }  

 

你可能感兴趣的:(swap,STL,iter_swap)