A specific solution for the template in vc6

Source: Internet
Author: User
Special template in vc6

As we all know, vc6 templates do not support special features.

In recent days, we have to try to implement some special examples in vc6.

First, calculate the maximum common divisor of M and N. The general functions are as follows:

Int gcd (int m, int N)

{

If (n = 0) return m;

Return gcd (n, m % N );

}

The code for bitwise template (calculate the maximum number of common contracts during the compilation period) is as follows:

Template <int M, int n>

Struct static_gcd

{

Enum {value = static <n, m % N >:: value };

}

 

Template <int m>

Struct static_gcd <m, 0>

{

Enum {value = m };

};

Because vc6 does not support bitrate conversion, this Code cannot be compiled. However, we can bypass this problem:

Template <int M, int n>
Struct static_gcd
{
Template <int unused>
Struct n_traits
{
Enum {value = static_gcd <n, m % N >:: value };
};
 
Template <>
Struct n_traits <0>
{
Enum {value = m };
};
 
Enum {value = n_traits <n >:: value };
};

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.