What is the relationship between model program design (GP) and model and template?

Source: Internet
Author: User

Generics are a concept. templates in C ++ support and implement generics.
---------------------------------------------------------------

To put it simply, generic programming is a kind of thinking model that "converts data types into values. The C ++ template mechanism is a specific vehicle of generic technology. In C ++, whether it is functions or classes, you can represent the data type required in it as a retainer (placeholder). This retainer is also called a template parameter. For example, the function template is as follows:

Template <typename T1, typename T2)
Void func (T1 param1, T2 param2 ){/*...*/}

Or class template:

Template <typename T1, typename T2)
Class {/*...*/}

Once the function func () or Class A is used in the program:

Func (5, 2.3 );
A <int, double>;

The compiler automatically exports a letter object or Class Object Based on the function template function reference or the class template reference. In other words, this current action is completed during compilation without increasing the cost of execution. (For the syntax and performance of the template, refer to any "young" C ++ full-picture book)

STL is a set of objects of the generic concept. Technically, it is actually a set of rigorous "Concepts" classifications. Here, the so-called concepts has a serious definition, which means "some condition requirements for a certain type 」. The models that meet these conditions is called the concepts. STL concepts does not actually correspond to anything in C ++ or other languages.
---------------------------------------------------------------

For C ++ programming
Generic programming is STL programming.
---------------------------------------------------------------

Generic programming and templates are technically similar, but not completely equivalent. Generic programming is an art and a kindProgramThe design concept (I can't think of a better word), and the template is a pure technology.
---------------------------------------------------------------

Generic programming is also called general programming,
MakeAlgorithmOr the structure can be independent of its details, that is, the type, to achieve a more advanced Abstraction
---------------------------------------------------------------

Generic is a method. How does a template use this method in C ++?

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.