Topic: typedef typename T::Member TypenameIsSoRedundantHere


Author: Markus Werle <numerical.simulation@web.de>
Date: Tue, 30 Apr 2002 18:52:19 GMT
Raw View
Hi!

during my hard tries to create portable C++ code
at least once in my life, I reengineered my project
and by that way also introduced namespaces
(these namespaces do not directly play a role
in this discussion. They only serve to show how
unreadable the code may become).

I give You a small snippet of my code:

namespace Diet
{
  namespace DefaultOps
  {

[...]

    template <class LHS, class RHS>
    inline
    Diet::Expr<Diet::BinOp<typename Diet::UnwrapExpr<typename
                           CRefOrVal<LHS>::Type>::Type,
                           typename Diet::UnwrapExpr<typename
                           CRefOrVal<RHS>::Type>::Type,
                           Diet::Addition> >
    operator+(const LHS& lhs, const RHS& rhs)
    {
      typedef typename Diet::UnwrapExpr<typename
          CRefOrVal<LHS>::Type>::Type LHT;
      typedef typename Diet::UnwrapExpr<typename
          CRefOrVal<RHS>::Type>::Type RHT;
      typedef Diet::BinOp<LHT, RHT, Diet::Addition> BO;
      typedef typename Diet::Expr<BO> ReturnType;

      return ReturnType(BO(LHT(unwrap_expr(lhs)), RHT(unwrap_expr(rhs))));
    }

[...]

  }
}

If I understood the rules correctly, my excessive use of "typename"
is required by the standard.

if (I.AmWrong())
{
  Tell(Me);
  exit; // ignore rest of message
}

What drives me mad is the use of keyword "typename" in all the typedefs.
Not only renders this my code completely unreadable, but I do not see
any usefulness for insisting on typename here.

Of course there are rare cases where keyword typename can help
to disambiguate the code, but here I do not understand the C++ rules at all:

after keyword typedef there is only the possibility
to place the name of a type.
So the gain of using keyword typename is exactly 0 here.

The information "T::Member is a type" in
typedef typename T::Member Example;
is already given by using the keyword "typedef".

IMHO
typedef T::Member Example;
is so strongly disambiguated and clear for the compiler,
there is no need to require keyword typename in addition here.

At least one popular compiler (GNU g++-3.0.4) gets it right all the time
if I do not set the flag -ansi, but of course other compilers require
keyword typename to be there.

Please give me a good reason why to insist on the rule here
and if You do not find one, remove the rule.


Markus




---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]