Expression Template - Extended Name Length

I get a “Named Name Length” warning from my code. I looked at SO answers for similar questions. * NB I know how to disable this (pragma), I also know that this is a warning that I can “ignore”, and that UNIX-based compilers may not highlight it: P *

There is a practical element to this question: if I get errors, I have to wade through rather awful text and templates. These errors are mainly related to typos at present, but if I had something subtle, it would be a nightmare to actually find what the problem is.

My code compiles and works, but as I said above, I get a warning. I have a "relatively" small expression

... auto expression = (l,aComma,w,aComma,x,aComma,y,aComma,z); std::cout << expression; 

which I generate from the comma operator that I defined for my expression template (I can send a message if necessary, but try to keep this minimum amount).

 // //Expression // template < class E > struct Expr { E expr_; Expr (E e) : expr_ (e) {} std::ostream& print(std::ostream& out) { return expr_.print(out); } }; template < class L, class H, class OP > struct BinExpr { L l_; H h_; BinExpr (L l, H h) : l_ (l), h_ (h) {} std::ostream& print(std::ostream& out) { l_.print(out) ; return h_.print(out); } }; template< class A, class B > Expr< BinExpr< Expr<A>, Expr<B>, Print<Expr<A>,Expr<B> > > > operator , ( Expr<A> a, Expr<B> b ) { typedef BinExpr < Expr<A>, Expr<B>, Print<Expr<A>,Expr<B> > > ExprT; return Expr<ExprT>(ExprT(a,b)); } 

The Microsoft page talks about refactoring to avoid this warning. MS wraps each level in a simple struct , which then contains the element template element . The problem is that the whole point of writing an expression template is to use an implicit construct to create a tree of required objects, avoiding the need to determine exactly what I will create. So that...

  • The question I want to ask is, can I somehow remove the length without losing function and flexibility?

  • Or can I somehow use the Microsoft proposal to wrap parts of structures, again, without losing function and flexibility? I can do this for the types that I will use in Expr objects, since I will set them before "listing" them between commas. But the length will increase as I add more items, and it will probably hit this limit again. I will also add extra complexity as I add a new feature. They will be created in a similar way and will most likely generate more headaches ...

  • Are there any C ++ 11 features that I could use to help? I tried the return type, but the internal typedef was invalid (and I'm not sure if that would help).


+6
source share
1 answer

Whenever I came across this warning and looked at refactoring the code so that the warning would not be emitted, I found that refactoring was not possible. If I did not need all of these template parameters, I would not have them there in the first place.

The MS page also says:

However, the correctness of the program does not depend on the truncated name.

Based on this fact, my SOP is in the #pragma warning:

#pragma warning( disable: 4503 )

This solution is a bit like an atomic bomb, I admit. However, this is the only instance in which I actually ignore the compiler warning at any level, and I believe that it can be safely ignored.

+4
source

All Articles