1
0
forked from boostorg/core

Merge pull request #3 from awulkiew/feature/ignore_unused

Feature/ignore unused
This commit is contained in:
Peter Dimov
2014-06-02 22:17:59 +03:00
5 changed files with 172 additions and 0 deletions

View File

@@ -37,6 +37,10 @@ Currently, the Core library contains:
[[@../../enable_if.html enable_if]] [[@../../enable_if.html enable_if]]
[`boost::enable_if`] [`boost::enable_if`]
] ]
[
[[link core.ignore_unused ignore_unused]]
[`boost::ignore_unused`]
]
[ [
[[link core.lightweight_test lightweight_test]] [[link core.lightweight_test lightweight_test]]
[`BOOST_TEST, BOOST_ERROR, BOOST_TEST_EQ, BOOST_TEST_NE, [`BOOST_TEST, BOOST_ERROR, BOOST_TEST_EQ, BOOST_TEST_NE,
@@ -75,6 +79,7 @@ Currently, the Core library contains:
[include:core addressof.qbk] [include:core addressof.qbk]
[include:core checked_delete.qbk] [include:core checked_delete.qbk]
[include:core explicit_operator_bool.qbk] [include:core explicit_operator_bool.qbk]
[include:core ignore_unused.qbk]
[include:core lightweight_test.qbk] [include:core lightweight_test.qbk]
[include:core no_exceptions_support.qbk] [include:core no_exceptions_support.qbk]
[include:core noncopyable.qbk] [include:core noncopyable.qbk]

29
doc/ignore_unused.qbk Normal file
View File

@@ -0,0 +1,29 @@
[section:ignore_unused Header <boost/core/ignore_unused.hpp>]
The header `<boost/core/ignore_unused.hpp>` defines the function template
`boost::ignore_unused()`. It may be used to suppress the "unused variable" or
"unused local typedefs" compiler warnings when the variable or typedef
can't be removed or commented out, e.g. when some blocks of the code are
conditionally activated. C++11 variadic templates are used if they're supported,
otherwise they're emulated with overloads.
`boost::ignore_unused()` was contributed by Adam Wulkiewicz.
Usage
boost::ignore_unused(v1, v2, v3);
boost::ignore_unused<T1, T2, T3>();
Example
int fun( int foo, int bar )
{
boost::ignore_unused(bar);
#ifdef ENABLE_DEBUG_OUTPUT
if ( foo < bar )
std::cerr << "warning! foo < bar";
#endif
return foo + 2;
}
[endsect]

View File

@@ -0,0 +1,70 @@
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CORE_IGNORE_UNUSED_HPP
#define BOOST_CORE_IGNORE_UNUSED_HPP
#include <boost/config.hpp>
namespace boost {
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
template <typename... Ts>
inline void ignore_unused(Ts const& ...)
{}
template <typename... Ts>
inline void ignore_unused()
{}
#else
template <typename T1>
inline void ignore_unused(T1 const&)
{}
template <typename T1, typename T2>
inline void ignore_unused(T1 const&, T2 const&)
{}
template <typename T1, typename T2, typename T3>
inline void ignore_unused(T1 const&, T2 const&, T3 const&)
{}
template <typename T1, typename T2, typename T3, typename T4>
inline void ignore_unused(T1 const&, T2 const&, T3 const&, T4 const&)
{}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
inline void ignore_unused(T1 const&, T2 const&, T3 const&, T4 const&, T5 const&)
{}
template <typename T1>
inline void ignore_unused()
{}
template <typename T1, typename T2>
inline void ignore_unused()
{}
template <typename T1, typename T2, typename T3>
inline void ignore_unused()
{}
template <typename T1, typename T2, typename T3, typename T4>
inline void ignore_unused()
{}
template <typename T1, typename T2, typename T3, typename T4, typename T5>
inline void ignore_unused()
{}
#endif
} // namespace boost
#endif // BOOST_CORE_IGNORE_UNUSED_HPP

View File

@@ -36,4 +36,8 @@ test-suite "core"
[ compile-fail explicit_operator_bool_compile_fail_conv_pvoid.cpp ] [ compile-fail explicit_operator_bool_compile_fail_conv_pvoid.cpp ]
[ compile-fail explicit_operator_bool_compile_fail_delete.cpp ] [ compile-fail explicit_operator_bool_compile_fail_delete.cpp ]
[ compile-fail explicit_operator_bool_compile_fail_shift.cpp ] [ compile-fail explicit_operator_bool_compile_fail_shift.cpp ]
[ compile ignore_unused_test.cpp : <toolset>gcc:<cxxflags>"-Wunused-variable -Wunused-local-typedefs -Werror"
<toolset>clang:<cxxflags>"-Wunused-variable -Werror"
<toolset>msvc:<cxxflags>"/we4100 /we4101" ]
; ;

View File

@@ -0,0 +1,64 @@
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/core/ignore_unused.hpp>
int main()
{
{
int a;
boost::ignore_unused(a);
}
{
int a, b;
boost::ignore_unused(a, b);
}
{
int a, b, c;
boost::ignore_unused(a, b, c);
}
{
int a, b, c, d;
boost::ignore_unused(a, b, c, d);
}
{
int a, b, c, d, e;
boost::ignore_unused(a, b, c, d, e);
}
{
typedef int a;
boost::ignore_unused<a>();
}
{
typedef int a;
typedef int b;
boost::ignore_unused<a, b>();
}
{
typedef int a;
typedef int b;
typedef int c;
boost::ignore_unused<a, b, c>();
}
{
typedef int a;
typedef int b;
typedef int c;
typedef int d;
boost::ignore_unused<a, b, c, d>();
}
{
typedef int a;
typedef int b;
typedef int c;
typedef int d;
typedef int e;
boost::ignore_unused<a, b, c, d, e>();
}
return 0;
}