C++ Template Metaprogramming

For the past year Aleksey Gurtovoy and I have been working on a new book, titled _C++ Template Metaprogramming: Concepts, Tools and Techniques from Boost and Beyond_. The book has recently entered copyediting. If you're interested you can peruse some sample chapters at http://boost-consulting.com/mplbook. Regards, Dave -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

Ok this is bit off topic since it isn't directly related to boost, but I know there are a lot C++ guru's here, and I'm sure one of you has addressed this. I am using Andrei's ScopeGuard and not boosts. I have googled, but I haven't figured out how to turn off the "unused variable" warning in g++, with out disabling all warnings. My guess is that there is no solution, but I thought I would try here first. TIA, Christopher

Unless I'm missing something, this should do the trick:
g++ -c -O2 -Wall -Wno-unused-variable foo.cpp
I was hoping there was some way to modify ON_BLOCK_EXIT, so I could leave the unused variable warning, but only disable it for ScopeGuard with a pragma.

"Christopher Baus"
Unless I'm missing something, this should do the trick:
g++ -c -O2 -Wall -Wno-unused-variable foo.cpp
Ok, I found the solution. I was looking for a pragma to do it, but the solution for gcc is the use the unused attribute.
I think an idiomatic solution is : int unused ; unused ; --drkm, en recherche d'un stage : http://www.fgeorges.org/ipl/stage.html

"drkm"
Unless I'm missing something, this should do the trick:
g++ -c -O2 -Wall -Wno-unused-variable foo.cpp
Ok, I found the solution. I was looking for a pragma to do it, but the solution for gcc is the use the unused attribute.
I think an idiomatic solution is : int unused ; unused ; Rene Rivera proposed this: namespace boost { namespace detail { inline void no_unused_variable_warning(void*) { } } } #define BOOST_NO_UNUSED_VARIABLE_WARNING(v) \ ::boost::detail::no_unused_variable_warning(&(v)) See namespace boost { namespace detail { inline void no_unused_variable_warning(void*) { } } } http://lists.boost.org/MailArchives/boost/msg54904.phpJonathan

"Christopher Baus"
Joaquín M López Muñoz has a version of Anrei's scope guard in his recently accepted multi_index library. To prevent these warnings, he adds a no-op member void touch() cont { } to scope_guard_impl_base. Then, in his version of ON_BLOCK_EXIT (which is customized for his library, and so not generally useful) expands to something like this: const scope_guard_impl_base& guard = make_guard( ... ); guard.touch(); Jonathan

"Christopher Baus"
Yep. It should suppress warnings on other compilers too, and makes the code easier to understand. Jonathan
participants (5)
-
Christopher Baus
-
David Abrahams
-
drkm
-
Jonathan Turkanis
-
Stephen Jackson