C ++ standard library section 4.4--min, Max function implementation

Source: Internet
Author: User
// 4_4.h // Implementation of the maximum and minimum functions // C ++ standard library section 4.4 namespace my_minmax {template <class T> inline const T & min (const T &, const T & B) {return B <? B: A;} template <class T> inline const T & MAX (const T & A, const T & B) {return a <B? B: A;} template <class T, class compare> inline const T & min (const T & A, const T & B, compare comp) {return comp (B, a )? B: A;} template <class T, class compare> inline const T & MAX (const T & A, const T & B, compare comp) {return comp (, B )? B: A;} bool int_ptr_less (int * a, int * B) {return * A <* B ;}} // 4_4.cpp # include <iostream> # include "4_4.h" using namespace my_minmax; int main () {int A = 1; int B = 2; int * pA = &; int * pb = & B; STD: cout <min (a, B) <STD: Endl; STD: cout <* min (Pa, Pb, int_ptr_less) <STD: Endl; // The implementation of this min function is interesting STD: cout <min (a, B) + 10 <STD: Endl; // The Return Value of the min function is of the reference type. It can be either the right or the left, for example, min (a, B) = 10}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.