C ++ template metaprogramming is bullshit

Source: Internet
Author: User

C ++ template metaprogramming is bullshit

 

After learning the so-called template meta-programming, I think the C ++ template meta-programming is a waste. You can say it can simplify the computing time. Well, what other functions do you have in addition to the so-called classic examples? It is said that Turing is complete, and even a function called during compilation cannot be processed, as shown in the following example:

Template <int degree>

Struct sinval

{

Enum {m_inner_val = (INT) (sin (float) (Degree/360) * 3.14) * 1000 )};

Static float getval ()

{

Return (m_inner_val/1000 );

}

};

I originally wanted to use it to implement a quick version of sin, and the result compiler could not handle it! In fact, the so-called template metaprogramming can all be implemented using the most concise method in C ++. You only need to assign the values you need to directly assign values to constants in a class in advance. What is this aircraft.

Furthermore, on the surface, metaprogramming reduces the amount of code, but after compilation, it will actually "instantiate" many class types. And the key is that the meta-programming must be able to determine the parameter value in the compiler, with a usage.

 

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.