1

Topic: That gives template metaprogramming (in comparison with others

In a C ++ there is a mechanism template metaprogramming. In C#, Java there is no what mechanism (is not present after all?). The question in that what advantages in comparison with C#, Java gives to pluses sample metaprogramming? Whether there is what that specific targets which it is impossible or to solve very difficultly on C#, Java but rather easily it is possible to solve on pluses? Whether it is felt in C#, Java absence of sample metaprogramming or there instead of it any other mechanisms are available which compensate absence of sample metaprogramming? It is possible also other languages for an example to consider. A question NOT about the generalized programming (usage of the parametrized classes and algorithms). A question about sample metaprogramming (an essence that calculations at a compilation stage are Turing-complete).

2

Re: That gives template metaprogramming (in comparison with others

At me too a question that you would make what to find answers to the questions independently? And whether you work over yourselves that in the future to find answers independently?

3

Re: That gives template metaprogramming (in comparison with others

Hello, Maxim Rogozhin, you wrote: whether > It is felt in C#, Java absence of sample metaprogramming or there instead of it any other mechanisms are available which compensate absence of sample metaprogramming? In the core manage normal dynamic polymorphism of runtime.

4

Re: That gives template metaprogramming (in comparison with others

Hello, Maxim Rogozhin, you wrote: > In a C ++ there is a mechanism template metaprogramming. In C#, Java there is no what mechanism (is not present after all?) . The question in that what advantages in comparison with C#, Java gives to pluses sample metaprogramming? For this purpose it is necessary to try to solve any practical task. For example, implementation  matrix operations for game/graphic engines. For example, in a C ++ it is enough to implement pair triple  classes and operations in between: template <size_t N, typename = double> class Vector; template <size_t M, size_t N, typename = double> class Matrix; template <size_t N, typename = double> class Quaternion; It turns out compactly and as much as possible effectively. A sledujushchijushchy step - to try to make the same on C# or on Java, to feel disappointment after a cruel regional ohm and to implement at first all possible variants of classes which can  in an ordinary game engine: class Vector2Double; class Vector2Float; class Vector3Double; class Vector3Float; class Vector4Double; class Vector4Float; class Matrix2x2Double; class Matrix2x2Float; class Matrix3x3Double; class Matrix3x3Float; class Matrix3x4Double; class Matrix3x4Float; class Matrix4x4Double; class Matrix4x4Float; class Quaternion2Double; class Quaternion2Float; class Quaternion3Double; class Quaternion3Float; Then to implement all possible variants of operations between these classes for what, I ask to note it is necessary to write code lines on pair orders more than in  a variant. Well and, at last, to try  all it , sorry for my French, in any real  and, after samplings FPS, to understand that all this time has been spent for nothing.

5

Re: That gives template metaprogramming (in comparison with others

Hello, rg45, you wrote: R> For this purpose it is necessary to try to solve any practical task. For example, implementation  matrix operations for game/graphic engines. For example, in a C ++ it is enough to implement pair triple  classes and operations in between: R> R> template <size_t N, typename = double> class Vector; R> template <size_t M, size_t N, typename = double> class Matrix; R> template <size_t N, typename = double> class Quaternion; R> On mine you speak about the generalized programming (usage of the parametrized classes and algorithms)? And my question about sample metaprogramming (i.e. an essence that calculations at a compilation stage are Turing-complete).

6

Re: That gives template metaprogramming (in comparison with others

Hello, reversecode, you wrote: R> at me too question R> that you would make what to find answers to the questions independently? R> and whether you work over yourselves that in the future to find answers independently? Any boorish question. It is interesting to listen alive to real people.

7

Re: That gives template metaprogramming (in comparison with others

Hello, rg45, you wrote: R> class Vector2Double;... R> class Vector4Float; R> class Matrix2x2Double;... R> class Matrix4x4Float; R> class Quaternion2Double;... R> class Quaternion3Float; It was recalled, in Delfi-7 there are no templates, but it is possible  similar with the help {$INC}, I truth such did only for sorting. But it is the answer only on first half of question. Second half - whether  sample meta-perversions?

8

Re: That gives template metaprogramming (in comparison with others

The author generates on some questions in a week on a subject With ++ and they almost  all answers can be found in Google therefore my question reasonable, the author is engaged ? Or than that another? I wait from the author next  - "And what for it is necessary With ++?"

9

Re: That gives template metaprogramming (in comparison with others

Hello, T4r4sB, you wrote: TB> But it is the answer only on first half of question. TB> second half - whether  sample meta-perversions? Well we take for example the bare - we want to implement operation of scalar product of two vectors of the arbitrary type (though it is possible and  numbers of vectors, but  to complicate directly at once). Reasonable, in my opinion, implementation should look approximately so: template <size_t N, typename T, typename U> ProductType <T, U> dotproduct (const Vector <N, T>& t, const Vector <N, U>& u) {return std:: inner_product (t.begin (), t.end (), u.begin (), ProductType <T, U> ());} And here practically at once we feel desire to use "meta-perversion" ProductType which can be implemented in the elementary image: typename <typename T, typename U> using ProducType = decltype (std:: declval <T> () * std:: declval <U> ()); And the further in wood, the  guerrillas: is mandatory there comes the moment when we wants to use more difficult specializations so and SFINAE - it is inevitable, by my experience. Thus, my solid  if we manage to justify expediency of application of templates as those, together with it we automatically justify expediency of "meta-perversions" as you them name.

10

Re: That gives template metaprogramming (in comparison with others

Hello, rg45, you wrote: R> Hello, T4r4sB, you wrote: TB>> But it is the answer only on first half of question. TB>> second half - whether  sample meta-perversions? R> well we take for example the bare - we want to implement operation of scalar product of two vectors of the arbitrary type (though it is possible and  numbers of vectors, but  to complicate directly at once). Reasonable, in my opinion, implementation should look approximately so: R> R> template <size_t N, typename T, typename U> R> ProductType <T, U> dotproduct (const Vector <N, T>& t, const Vector <N, U>& u) R> {R> return std:: inner_product (t.begin (), t.end (), u.begin (), u.end (), ProductType <T, U> ()); R>} R> Why not auto result = t [0] *u [0]; for (int i=1; i <N; ++ i) result + = t [i] *u [i]; return result;? fix: here  I , I in 3 lines was sealed up,

11

Re: That gives template metaprogramming (in comparison with others

Hello, T4r4sB, you wrote: TB> Why not TB> TB> auto result = t [0] *u [i]; TB> for (int i=1; i <N; ++ i) result + = t [i] *u [i]; TB> return result; TB> TB>? Because this unjustified complication of the code. Instead of one simple expression - superfluous branchings, superfluous local variables - all it demands more debugging and the big expenses for a covering units-tests. On a simple example it, certainly not so is felt, but at implementation more challenging tasks my approach gives notable simplification of the code and increase of its reliability. Because any  is written and tested once, and used everywhere.

12

Re: That gives template metaprogramming (in comparison with others

R> Well we take for example the bare - we want to implement operation of scalar product of two vectors of the arbitrary type (though it is possible and  numbers of vectors, but  to complicate directly at once). Reasonable, in my opinion, implementation should look approximately so: it is reasonable not to undertake the task where it is necessary to complicate all, and to simplify the task, to implement it in sufficient volume and with sufficient technical characteristics. The arbitrary number is a complication. It is really necessary in your activity? To you the manual selects money for implementation of this madness? R> thus, my solid  if we manage to justify expediency of application of templates as those, together with it we automatically justify expediency of "meta-perversions" as you them name. No, it is the perverted idea going from desire to be perverted to a limit. Really the programmer has nothing to be engaged, except making of all was more general-purpose there is no place? And for such feat to it that will be? Present that you transfer this idea on mechanical engineering. The machine what in minimum alteration can be transformed to the tank, a tractor or the submarine is necessary to you?  then to be engaged in this perversion in programming? Yes, here speed of changes much faster than in the real world and easily gives in to influence from the programmer. But it does not mean that such speed of changes should lead to that all should be general-purpose to a limit.  that that the author of a subject directs attention on Turing-complete it is similar to trolling. Because it is not necessary Turing-complete metaprogramming on templates in real vital tasks. And to compare to other languages it is not necessary. Would be madness to write a three-dimensional engine of real time on  or c#. These languages are far from equipment (new commands of the processor), do not support effective GPU calculation, for example CUDA, etc. In these applications templates well gain together with low-level access to storage and to the processor. But also as metaprogramming here does not smell. Probably, in any applications it is useful, but personally I in the practice did not meet from such need. I only read about such possibility at Aleksandresku when he tried to implement it within the limits of an old C ++. It was monstrously bulky. Now language change moves to possibility all it to write much more shortly and more conveniently and sooner or later at us appear convenient sample IF, cycles and other, in one simple line with convenience #IFDEF. Then all it will be actual and probably it leads to a new class of libraries. But, my deep , these the task for scientists. Let they are engaged in search and a find of new receptions of programming, and I personally now the next three years have a task of creation of specific programs for three platforms: win, mac, linux, than I also am engaged. And here check, even close the head is not occupied from me metaprogramming, but here it is necessary to potter with a difference between platforms both originating reefs and singularities. Here at all before coding. It is a question of compromises and search of technical ideas of overcoming of originating complexities. If I also about  thought, my project would be tightened years on five, the ten programmers and many millions roubles would demand. And so I pull all and even I have free time.

13

Re: That gives template metaprogramming (in comparison with others

Hello, T4r4sB, you wrote: R>> Well we take for example the bare - we want to implement operation of scalar product of two vectors of the arbitrary type (though it is possible and  numbers of vectors, but  to complicate directly at once). Reasonable, in my opinion, implementation should look approximately so: R>> R>> template <size_t N, typename T, typename U> R>> ProductType <T, U> dotproduct (const Vector <N, T>& t, const Vector <N, U>& u) R>> {R>> return std:: inner_product (t.begin (), t.end (), u.begin (), u.end (), ProductType <T, U> ()); R>>} R>> TB> Why not TB> TB> auto result = t [0] *u [i]; TB> for (int i=1; i <N; ++ i) result + = t [i] *u [i]; TB> return result; TB> TB>? In components to told above - in my variant there is a possibility to specify type of returned value explicitly, in your case is only auto and  the code suffers.

14

Re: That gives template metaprogramming (in comparison with others

Hello, rean, you wrote: R>> Well we take for example the bare - we want to implement operation of scalar product of two vectors of the arbitrary type (though it is possible and  numbers of vectors, but  to complicate directly at once). Reasonable, in my opinion, implementation should look approximately so: R> it is reasonable not to undertake the task where it is necessary to complicate all, and to simplify the task, to implement it in sufficient volume and with sufficient technical characteristics. The arbitrary number is a complication. It is really necessary in your activity? R> to you the manual selects money for implementation of this madness? Did not read Many letters - a sign  in a head,  further.

15

Re: That gives template metaprogramming (in comparison with others

Hello, rg45, you wrote: R> In components to told above - in my variant there is a possibility to specify type of returned value explicitly, in your case is only auto and  the code suffers. It agree, auto generally fierce harm. It is improbably fashionable, type to go nuts what output of types,  to write faster, but it is impossible to read.  this perversion caused by that in 2018 in crosses did not deliver till now statics , but all the same it seems to me that in real programs it can be bypassed, not especially something losing.

16

Re: That gives template metaprogramming (in comparison with others

Hello, T4r4sB, you wrote: TB> Sfinae is a perversion caused by that in 2018 till now in crosses did not deliver statics , but all the same it seems to me that in real programs it can be bypassed, not especially something losing. Here I will disagree, very useful piece, there, where normal specializations do not consult. For example, very much sometimes gain specializations in availability of certain operation for the given input types. It is possible to bypass, of course, but only by code inflating, occasionally, rather painful.

17

Re: That gives template metaprogramming (in comparison with others

R> did not read Many letters - a sign  in a head,  Further. And you esteem. And with a pencil. Think over each thought. That look and from metaprogramming perversions leave. Become the healthy programmer, and can be even the programming engineer.

18

Re: That gives template metaprogramming (in comparison with others

Hello, rean, you wrote: R> And you esteem. And with a pencil. Think over each thought. That look and from metaprogramming perversions leave. Become the healthy programmer, and can be even the programming engineer. Thanks, for care, but I somehow will manage.

19

Re: That gives template metaprogramming (in comparison with others

auto and  the code suffers. TB> it agree, auto generally fierce harm. It is improbably fashionable, type to go nuts what output of types,  to write faster, but it is impossible to read. Last night I applied auto in several places when checked a new piece of the code on Linux and Mac OS that allowed to get rid me of several tens platform #IFDEF and not to lose compatibility with old compilers and old platforms, allowed not to lose in speed of calculations what would be supposed without #IFDEF. If  means of language with mind, it in the help. If you push for the sake of a mode, to yourself spiteful .

20

Re: That gives template metaprogramming (in comparison with others

Hello, rg45, you wrote: R> Sledujushchijushchy a step - to try to make the same on C# or on Java, to feel disappointment after a cruel regional ohm and to implement at first all possible variants of classes which can  in an ordinary game engine: R> R> class Vector2Double; R> class Vector2Float; R> class Vector3Double; R> class Vector3Float; R> class Vector4Double; R> class Vector4Float; R> class Matrix2x2Double; R> class Matrix2x2Float; R> class Matrix3x3Double; R> class Matrix3x3Float; R> class Matrix3x4Double; R> class Matrix3x4Float; R> class Matrix4x4Double; R> class Matrix4x4Float; R> class Quaternion2Double; R> class Quaternion2Float; R> class Quaternion3Double; R> class Quaternion3Float; R> Why not class Vector <T> {public Vector (int len) {...}} class Matrix <T> {public Matrix (int len1, int len2) {...}} class Quaternion <T> {public Quaternion (int len) {...}}

21

Re: That gives template metaprogramming (in comparison with others

Hello, AlexRK, you wrote: ARK> Why not ARK> ARK> class Vector <T> {public Vector (int len) {...}} ARK> class Matrix <T> {public Matrix (int len1, int len2) {...}} ARK> class Quaternion <T> {public Quaternion (int len) {...}} ARK> Well at least because in C#, for example, to you will not be accessible any arithmetical  over elements - neither to add, nor to subtract increase - you can try, if you do not trust. As it is sad, but  C# is at all the same that C templates ++,  not some similarity. Thus about high-speed performance even to speak there is no sense

22

Re: That gives template metaprogramming (in comparison with others

Hello, rean, you wrote: R> it is reasonable not to undertake the task where it is necessary to complicate all, and to simplify the task, to implement it in sufficient volume and with sufficient technical characteristics. The arbitrary number is a complication. It is really necessary in your activity? R> to you the manual selects money for implementation of this madness? It not madness. Here is how time this example though is simple, but quite vital. At a stage to setting of the task for the same image processing can seem that the type float suffices for eyes. And then the picture comes to 16 bit per pixel from a thermal imager and for accuracy of some filters is already necessary double. Or int. It appears that the generalized record of algorithms  and saves time.

23

Re: That gives template metaprogramming (in comparison with others

Hello, AlexRK, you wrote: ARK> Why not ARK> ARK> class Vector <T> {public Vector (int len) {...}} ARK> class Matrix <T> {public Matrix (int len1, int len2) {...}} ARK> class Quaternion <T> {public Quaternion (int len) {...} } ARK> R> Well at least because in C#, for example, to you will not be accessible any arithmetical  over elements - neither to add, nor to subtract increase - you can try, if you do not trust. In addition to the previous post: if, all the same, you will select time to experiment, try to implement on C# here such example cut down to a minimum: https://ideone.com/TOyuvM #include <array> #include <iostream> #include <numeric> #include <type_traits> #include <utility> template <typename T, typename U> using ProductType = decltype (std:: declval <T> () * std:: declval <U> ()); template <size_t N, typename T = double> using Vector = std:: array <T, N>; template <size_t N, typename T, typename U> ProductType <T, U> dotproduct (const Vector <N, T>& t, const Vector <N, U>& u) {return std:: inner_product (t.begin (), t.end (), u.begin (), ProductType <T, U> ());} int main () {const Vector <3, short> v1 {1, 2, 3}; const Vector <3, signed char> v2 {1, 2, 3}; auto res = dotproduct (v1, v2); static_assert (std:: is_same <int, decltype (res)>:: value, "Unxpected return type"); std:: cout <<res <<std:: endl;}

24

Re: That gives template metaprogramming (in comparison with others

Hello, rg45, you wrote: ARK>> Why not ARK>> ARK>> class Vector <T> {public Vector (int len) {...}} ARK>> class Matrix <T> {public Matrix (int len1, int len2) {...}} ARK>> class Quaternion <T> {public Quaternion (int len) {...}} ARK>> R> Well at least because in C#, for example, to you will not be accessible any arithmetical  over elements - neither to add, nor to subtract increase - you can try, if you do not trust. Why it will not be? You do methods Add, Multiply, Divide, and all is accessible. Or the vulnerable soul of the programmer demands tags "+" and "-"?

25

Re: That gives template metaprogramming (in comparison with others

Hello, rg45, you wrote: R> In addition to the previous post: if, all the same, you will select time to experiment, try to implement on C# here such example cut down to a minimum: And it is possible to tell, what this example does?