Re: Is this proper template specialization?

Discussion in 'C++' started by Victor Bazarov, Jul 31, 2003.

  1. "mjm" <> wrote...
    > I have to compute the return type of a matrix operation.
    > In general the return type is the most general "Rectangular".
    > But if the two operands have the same type then this type will be the
    > return type.
    > (ie. UpperTriangular times UpperTriangular is again UpperTriangular,
    > Symmetric times Symmetric is Symmetric,...).
    >
    > So this is what I want to do (the general case):
    >
    > template<typename MatrixType1, typename MatrixType2>
    > struct MatrixResultType { typdef Rectangular type; }

    ;

    >
    > But if the two operands have the same type
    >
    > template<typename MatrixType>
    > struct MatrixResultType<MatrixType,MatrixType> { typedef MatrixType
    > type; }

    ;

    >
    >
    > I wonder if the compiler recognizes the second definition as a
    > specialization of the first one (ie. both template parameters equal).


    It should. It's what is known as "partial specialisation".
    Do you get an error? Post more code and compiler diagnostic
    messages.

    Victor
    Victor Bazarov, Jul 31, 2003
    #1
    1. Advertising

  2. Victor Bazarov

    mjm Guest

    "Victor Bazarov" <> wrote in message news:<>...
    > "mjm" <> wrote...
    > > I have to compute the return type of a matrix operation.
    > > In general the return type is the most general "Rectangular".
    > > But if the two operands have the same type then this type will be the
    > > return type.
    > > (ie. UpperTriangular times UpperTriangular is again UpperTriangular,
    > > Symmetric times Symmetric is Symmetric,...).
    > >
    > > So this is what I want to do (the general case):
    > >
    > > template<typename MatrixType1, typename MatrixType2>
    > > struct MatrixResultType { typdef Rectangular type; }

    > ;
    >
    > >
    > > But if the two operands have the same type
    > >
    > > template<typename MatrixType>
    > > struct MatrixResultType<MatrixType,MatrixType> { typedef MatrixType
    > > type; }

    > ;
    >
    > >
    > >
    > > I wonder if the compiler recognizes the second definition as a
    > > specialization of the first one (ie. both template parameters equal).

    >
    > It should. It's what is known as "partial specialisation".
    > Do you get an error? Post more code and compiler diagnostic
    > messages.



    Thanks for all replies.
    I wanted to make sure the compiler and I have the same view of what's
    going on.
    I am going to hack in a substantial amount of code and I don't want to
    find out via cryptic error messages that there is a divergence of
    opinion.
    >
    > Victor
    mjm, Jul 31, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David B. Held
    Replies:
    2
    Views:
    466
    Rob Williscroft
    Oct 26, 2003
  2. Dave
    Replies:
    4
    Views:
    7,664
    pdixtl
    Jun 4, 2010
  3. pit3k
    Replies:
    8
    Views:
    366
    Victor Bazarov
    Feb 9, 2005
  4. case2005
    Replies:
    3
    Views:
    1,800
    Nicolas Pavlidis
    Feb 13, 2005
  5. Joseph Turian
    Replies:
    2
    Views:
    463
Loading...

Share This Page