C++ 在编译时获取boost::函数arity?

C++ 在编译时获取boost::函数arity?,c++,function,boost,boost-preprocessor,C++,Function,Boost,Boost Preprocessor,我需要在BOOST\u PP\u IF语句中根据BOOST::function对象的arity(参数计数)做出决定。这可能吗 boost::function\u types::function\u arity实现了我想要的功能,但是在运行时;我在编译时需要它。函数性 function_arity template<typename F> struct function_arity; Header #include <boost/function_types/functio

我需要在
BOOST\u PP\u IF
语句中根据
BOOST::function
对象的arity(参数计数)做出决定。这可能吗

boost::function\u types::function\u arity
实现了我想要的功能,但是在运行时;我在编译时需要它。

函数性
function_arity

template<typename F>
struct function_arity;

Header

#include <boost/function_types/function_arity.hpp>

F

    Callable builtin type 
function_arity<F>

    Function arity as MPL - Integral Constant 
function_arity<F>::value

    Constant value of the function arity 
模板 结构函数性; 标题 #包括 F 可调用内置类型 函数性 作为MPL积分常数的函数算术 函数_arity::值 函数的常数值
注意,这是编译时常量

你应该从这里开始:


或者使用BOOST_PP_SEQ_FOR_EACH/BOOST_PP_REPEAT_FROM_TO生成针对
函数的if/else条件\u arity::value

出于某种原因,my includes持续中断但不在预览中=[

#include <ostream>  
#include <iostream>  
#include <boost/function.hpp>  

// Assume that you want to print out "Function is N-arity" for general case. But "nularity" for 0

template< int i >
struct DarkSide
{
template<class U>
void operator()(std::ostream& out, const U& u) { out << "Function is "<<i<<"-arity"<<u; }
void operator()(std::ostream& out, std::ostream& ( *pf )(std::ostream&) ) { out << "Function is "<<i<<"-arity"<<pf; }
};

template<>
struct DarkSide<0>
{
template<class U>
void operator()(std::ostream& out, const U& u) { out << "Function is nularity"<<u; }
void operator()(std::ostream& out, std::ostream& ( *pf )(std::ostream&) ) { out << "Function is nularity"<<pf; }
};

int main() {
typedef boost::function< void ( ) > vFv;
typedef boost::function< void ( int x ) > vFi;
DarkSide< vFv::arity >()(std::cout,"\n");
DarkSide< vFi::arity >()(std::cout,std::endl);
}
#包括
#包括
#包括
//假设您想要打印出“函数为N个数”作为一般情况,而“N个数”作为0
模板
结构暗箱
{
模板

void操作符()

#include <boost/function.hpp>
#include <iostream>
int main() {
  std::cout << boost::function<void()>::arity << std::endl;
  std::cout << boost::function<void(int)>::arity << std::endl;
  std::cout << boost::function<void(int, int)>::arity << std::endl;
}
#包括
#包括
int main(){

std::cout预处理器没有类型或值的概念,只有整数文本。它不知道函数是什么。只有模板提供编译时分支,而不是编译前作为单独阶段运行的预处理器。这无法根据要求在编译时获得函数的算术性。