Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-09-24 18:08:46


----- Original Message -----
From: <williamkempf_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, September 24, 2001 7:20 PM
Subject: [boost] Re: Config and "unused variables"

> --- In boost_at_y..., "Fernando Cacciola" <fcacciola_at_g...> wrote:
> >
> > ----- Original Message -----
> > From: <williamkempf_at_h...>
> > To: <boost_at_y...>
> > Sent: Monday, September 24, 2001 5:30 PM
> > Subject: [boost] Config and "unused variables"
> >
> >
> > > It's fairly common to have unused variables in Boost code for
> various
> > > reasons. For instance, a common work around for a VC++ bug is to
> > > have code such as:
> > >
> > > template <typename T>
> > > void foo(T* dummy=0)
> > > {
> > > }
> > >
> > > The dummy parameter is never used, and is there solely to help the
> > > VC++ compiler figure out the template argument types.
> > >
> > I think you are referring to the lack of explicit template
> instantation in
> > VC++. In that case you don't really need a name for the dummy
> argument, so
> > the usual workaround looks rather like this:
> >
> > template <typename T>
> > void foo(T const* =0)
> > {
> > }
> >
> > Anyway, I know there are places when you do have named unused
> variables.
>
> Even in this case I'd much prefer leaving the name, as I think it
> documents the idiom better. The documentation is even better when
> you include the unused_parameter() call.
>
Probably...

> > > Currently I don't
> > > see any mechanism for eliminating this stuff in the config files,
> >
> > With Borland 5.5.1, I'm used to do the following:
> >
> > void foo(MyClass const& a)
> > {
> > int b;
> > float c ;
> > (a,b,c); // ==> Removes the 'ununsed' warning while generating no
> code at
> > all.
> > }
> >
> > Unfortunately, I don't know how to analyze this idiom in terms of
> Standard
> > behavior, so I don't know how portable it is or what side effects
> can it
> > present.
>
> I think this is standards compliant, and is the underlying method
> usually used. However, it does a poor job of documenting anything,
> so in C one usually uses a macro that reduces to the above code. We
> all know to avoid macros, though, so the template technique does the
> same job in a safer manner.
>
Agreed.

> > > but
> > > Jeremy Siek has a simple solution in concept_check.hpp:
> > >
> > > template <class T> inline void ignore_unused_variable_warning
> (const
> > > T&) { }
> > >
> > > I think it would be beneficial to have this in a more reusable
> > > fashion for all Boost libraries and think the config files would
> be a
> > > handy place for it (though I'd be fine with it in any other
> location
> > > as long as it was a small header). I might reduce the name to
> just
> > > unused_variable(), though other's might not care for the less
> verbose
> > > name.
> > >
> > Sounds good. (I like unused_variable()).
> > I would have add the possibility of having multiple arguments:
> >
> > template<class T0> void unused_variable( T0 const& ) {}
> > template<class T0, class T1> void unused_variable( T0 const&, T1
> const& ) {}
> > template<class T0, class T1, class T2> void unused_variable( T0
> const&, T1
> > const&, T2 const& ) {}
> > etc...
>
> This may or may not be overkill for a simple concept.
>
How would this be overkill, exactly?
I can imagine the above template functions in config.hpp, so I can write
something like:

void foo ( MyClass const& c )
{
   int a ;
   float b ;

   unsused_variables(a,b,c);
}

And that looks pretty good to me.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk