Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2001-09-26 14:21:46


At 11:51 AM 9/26/2001, Darin Adler wrote:

>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,
>boost/graph/graph_concepts.hpp, boost/iterator_adaptors.hpp,
>boost/property_map.hpp, libs/concept_check/class_concept_check_test.cpp,
>libs/concept_check/stl_concept_covering.cpp,
>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:
>boost/python/detail/extension_class.hpp,
>boost/regex/detail/regex_format.hpp, boost/regex/detail/regex_match.hpp,
>boost/type_traits/type_traits_test.hpp,
>libs/concept_check/class_concept_fail_expected.cpp,
>libs/python/src/objects.cpp, libs/python/src/types.cpp,
>libs/python/test/comprehensive.cpp, libs/random/random_speed.cpp,
>libs/random/random_test.cpp, libs/regex/src/primary_transform.hpp,
>libs/regex/src/wide_posix_api.cpp,
libs/utility/counting_iterator_test.cpp,
>libs/utility/half_open_range_test.cpp, and in many of the tests in the
>libs/config/test directory.

Interesting. Note that those uses involve a number of different
developers, too, not just one person repeating a personal favorite
technique.

I wouldn't have guessed anywhere near that much use for either
technique. Makes a strong argument we should have something in Boost.

>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.

Pending more discussion, I lean toward the template too.

--Beman


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