我有一个非常奇怪的情况,我已经升级到BOOST到版本1_56_0并且以前很好的代码不再用gcc 4.7.3编译。
代码是一个简单的模板,用于确定类型是否为boost::variant
:
#ifndef BOOST_PP_IS_ITERATING
#ifndef BOOST_PP_TEST__H__
#define BOOST_PP_TEST__H__
#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/variant.hpp>
#include <boost/config.hpp>
/// ----------------------------------------------------------------------------|
/// namespace
/// ----------------------------------------------------------------------------|
namespace utils {
/// ----------------------------------------------------------------------------|
/// @brief primary trait template that returns false for non-variant types
/// @param T the type to check
template <class T>
struct is_variant_type
{ BOOST_STATIC_CONSTANT( bool, value = false ); };
/// ----------------------------------------------------------------------------|
// generate specializations of the is variant template
#define BOOST_PP_ITERATION_LIMITS (2, BOOST_VARIANT_LIMIT_TYPES )
#define BOOST_PP_FILENAME_1 "utils_lib_is_variant.h" // this file
#include BOOST_PP_ITERATE()
} // namespace
#endif // BOOST_PP_TEST__H__
#else // BOOST_PP_IS_ITERATING
/// ----------------------------------------------------------------------------|
/// Use boost pre-processor to generated template specializations for
/// boost::variants with 2 to BOOST_VARIANT_LIMIT_TYPES parameters
/// ----------------------------------------------------------------------------|
#define n BOOST_PP_ITERATION()
// specialization pattern
template <BOOST_PP_ENUM_PARAMS(n, class T)>
struct is_variant_type< boost::variant< BOOST_PP_ENUM_PARAMS(n,T) > >
{ BOOST_STATIC_CONSTANT( bool, value = true ); };
#undef n
#endif // BOOST_PP_IS_ITERATING
这段代码编译干净:
但是当使用GCC 4.7.3和BOOST版本1_56_0编译时,我收到以下错误:
In file included from /opt/miniboost_1_56_0/boost/preprocessor/iteration/detail/iter/reverse1.hpp:1294:0,
from /opt/miniboost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:43,
from utils_lib_is_variant.h:47,
from is_variant.cpp:6:
./utils_lib_is_variant.h:62:67: error: wrong number of template arguments (0, should be 1 or more)
In file included from /opt/miniboost_1_56_0/boost/variant/variant.hpp:28:0,
from /opt/miniboost_1_56_0/boost/variant.hpp:17,
from utils_lib_is_variant.h:28,
from is_variant.cpp:6:
/opt/miniboost_1_56_0/boost/variant/variant_fwd.hpp:291:53: error: provided for ‘template<class T0, class ... TN> class boost::variant’
In file included from /opt/miniboost_1_56_0/boost/preprocessor/iteration/detail/iter/reverse1.hpp:1294:0,
from /opt/miniboost_1_56_0/boost/preprocessor/iteration/detail/iter/forward1.hpp:43,
from utils_lib_is_variant.h:47,
from is_variant.cpp:6:
./utils_lib_is_variant.h:62:69: error: template argument 1 is invalid
我无法从GCC 4.7.3更改实时代码的编译器。 有一个简单的方法吗?目前我的选择是:
is_variant_type