I am trying to understand the patterns used in ublas. Pattern is such as:
straight vector: vector_expression & lt; Vector & gt; Where vector_xpressions are like this:
template & lt; Class E & gt; Square vector_expression {... // a constructor or e pointer / reference in the class / consent and operator () (const) {return * static_cast & lt; Const e * & gt; (this); } The complete source code is here:
My question is, how * static_cast
Next question: If I receive
template I have a compiler error in relation to the base in the stateless artist
Thanks
This is a trick to stop the task - type of template There are many concepts like Vector Expression, Scalar Expression, Matrix Expression etc. to restrict the category. If you want to write a function template that multiplies a vector with a scalar, you can try typing
template but it is not working because both announcements are essentially equal and no one says that V is considered to be a vector expression and S is a Scalar expression is considered. Therefore, ULL developers have to use CRTP to stop these templates:
template & lt; Typename V, typename S & gt; Some_Type operator * (vector_expression & lt; V & gt; ve, scalar_expression & lt; S & gt;); To create this function, all scalar expressions are assigned to scalar_expression & lt; S & gt; and all vector expressions V to vector_expression & lt; V> . In this way this operator is only considered if the fist operation is actually an expression for a vector and the second argument is actually an expression for a scalar. You can overload the templates of this function with another gate that swaps the parameter and everything is fine.
Now, to be able to access anything from V and S (derivative types), we have the conversion operator in base class for the base class derived class. Because the base class knows the derived class (this is a template parameter), this is not a problem. This means to choose the most vulnerable cast operator, which allows this artist to avoid errors. This is static_cast . It can be used to change base * without any significant overhead.
I do not know what you try to do with your code
template & lt; Class E & gt; Square vector_xpression 2: private vector_expression & lt; E & gt; If you want to write your own vector expression as a template, then you will do it like this:
template & lt; Class E & gt; Class my_parameterized_vector_expression: public vector_expression & lt; My_parameterized_vector_expression & lt; E & gt; & Gt ;; I do not think it works with private heritage. At least all the function templates that take vector expression as logic, if you use a personal heritage here, then the conversion operator will not be able to access it from the base class.
Comments
Post a Comment