|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-09-24 16:46:09
----- Original Message -----
From: <williamkempf_at_[hidden]>
To: <boost_at_[hidden]>
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.
> 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.
> 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...
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