| |

VerySource

 Forgot password?
 Register
Search
Author: zjzengjian

Discussion: Is template technology just a class library?

[Copy link]

0

Threads

41

Posts

28.00

Credits

Newbie

Rank: 1

Credits
28.00

 China

Post time: 2020-1-28 10:00:02
| Show all posts
Who said, there are many templates in my code, but templates are not necessarily generic, such as the usage in atl, forming an inheritance system. Eliminate virtual tables for static polymorphism.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-2 10:54:01
| Show all posts
kuo123456wrote:
> Template metaprogramming
> A hack

It isn't just a hack, actually it has already become a serious technique, which has had big impact on library construction.

cocheng8230 wrote:
> Is a representative of the academic school,
> But it represents the trend of future language development
> It takes a long time from academic to engineering application
> It is suggested that the landlord can look at the relevant reports of the 0x standard to know some situations.

Actually, templates originated techniques are as practical as any other language techniques. That it's originally motivated by the desire to construct an efficient and elegant container / algorithm library is the first clue and the most obvious evidence.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-5 21:30:02
| Show all posts
mark
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-2-10 18:15:01
| Show all posts
GP's relatively high-end application is probably WTL. Java has j2se, c # has .net, and c ++. Why can't there be a larger-scale paradigm framework? Is it really like the brother who said "For example, you need an FTP class for GP has no advantage in data transmission and reuse of FTP class. "
It may be that I have been doing OOP for too long, and my way of thinking can no longer be transformed into a GP, which is much more difficult than the original mode because I learned "Design Mode". Many algorithms in STL are quite suitable for using templates. Novices who know GP can think of template it with the first impression, but in high-end applications, you can hardly feel the advantages of GP, and I do n’t know who, what software , Have already tasted the benefits from GP modeling. . .
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-12 12:45:01
| Show all posts
I'm a newbie, know a little about templates, for example


First a template class e.g.
template <class T, class HandleType>
class StartThread
{
private:
        ..............;
public:
      HandleType Run (T&t)
      {
           ...;
           return t.run ();
      }


};

The template class means that this T has a member function that returns HandleType run ();
You can put this paragraph .....; return t.run (); This part of the code uses the linux version or win32 version of your library, etc. It is only related to run (); this text (macro can also )

But if you change to OO, this is what it looks like:

#if defined (_WIN32)

typedef void * MyLibHandle;

#else

typedef int MyLibHandle;

#endif

class AbstractRunnerable
{
virtual MyLibHandle run () = 0;

};

class StartThread
{
public:
       MyLibHandle Run (AbstractRunnerable&t)
        {
             .....;
             return t.run ();
        }
};

This is just a small example, maybe others have more elegant OO methods.

I personally think that both the run-time polymorphism of OO and the compile-time polymorphism of GP provide a function similar to control inversion.
In the final analysis, this GP StartThread or OO StartThread can only guarantee that a part of the code is fixed, they do not have complete behavior, and need external types to fill, inheriting AbstractRunnerable or
The meaning of StartThread <Runner> is to fill a behavior; I think that theoretically it doesn't matter which one you choose, but this is just some basic libraries, and their processes are basically fixed, such as vector, list, or thread , Most of their processes are fixed, such as sorting, etc., just need to inject an operator <and so on; GP is more suitable to express the concept of the process. The template pattern of the design pattern is almost the same;


However, in most software development, it may be the process that is constantly changing. At this time, the function of the packaging process (algorithm) provided by the GP is not very useful. You can use OO to express a type.
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-12 23:45:01
| Show all posts
The example I mentioned above also illustrates a problem, that is, the GP is more obscure, and it is easy to appear that HandleType lacks default constructors, etc., but the OO version is much clearer, but lacks elegance;

GP provides a self-healing ability of C ++. At least, it can formally provide a syntax similar to dynamic language for this language, but it is only formal.We should see that libraries such as boost or loki use a lot of hacks.&&template&&macro trick is only for achieving elegance in form (syntax). But this kind of thing may be considered boring in actual development.
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-15 23:15:01
| Show all posts
Using good interface inheritance can increase code reuse and avoid the use of templates, and you get some additional benefits.
However, the disadvantage is that dynamic chaining affects efficiency, and interfaces cannot be used at all times, and templates appear more free (there are many problems ...)
Reply

Use magic Report

1

Threads

39

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-5-28 15:15:02
| Show all posts
The mistake of the template will make people very depressed, but maybe it will be no problem if you are proficient.

Template technology can be used in many ways, it is not necessary to use, but if it feels appropriate, but find another way, this is not necessary.
For example, the container class of stl is worth emulating.Because of this application, the chance of error is relatively low.

In other respects, to use a template, you must carefully consider yourself and your comrades.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-14 17:15:01
| Show all posts
I think GP's business modeling is a trend, and there may be UML-like things dedicated to GP analysis in the future.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-16 14:00:01
| Show all posts
mark learning.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list