From: Darin Adler (darin_at_[hidden])
Date: 2001-09-26 10:51:56
on 9/26/01 4:13 AM, Beman Dawes at bdawes_at_[hidden] wrote:
> But isn't the usual practice in that case to wrap the temporary and store
> to it in an #ifndef NDEBUG?
A good way to see where this comes up is to look at the examples already in
Boost. In most cases, we just don't declare the variable or don't name it in
the parameter list, but there are a number of files that use one of the
techniques we're discussing.
The ignore_unused_variable_warning function template is used in 8 different
source files in Boost: boost/concept_check.hpp,
libs/utility/call_traits_test.cpp (called unused_variable in this file), and
libs/tuple/test/tuple_test_bench.cpp (called dummy in this file).
The cast to (void) technique is used in 32 different source files in Boost:
libs/utility/half_open_range_test.cpp, and in many of the tests in the
I find the function template more readable, more elegant, and perhaps
slightly more portable, since it relies on the "don't complain about
parameters without names" behavior rather than the "mentioning in an
expression that is unused is using a variable" behavior.
About 1/2 of the uses of the (void) technique also have a comment to explain
what the void cast means.
There can be overhead caused by the function template technique, though,
when the compiler is not doing function inlining. This is not an issue for
me, but it might be an issue for others.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk