我正在尝试围绕用 C 编写的 SQL 库实现 C++11 包装器。C 库具有单独的函数,用于从需要列索引的 SQL 语句中获取不同的数据类型。下面是一个简单的方法原型,但有一个严重的缺陷:它依赖于参数执行的顺序,这是不安全的(也可能有编译器错误,没有测试过)。
问题:在可变参数模板扩展中安全地递增变量的独立于平台的方法是什么?
template< typename... ColumnTypes >
void SQLStatement::execute( std::function< void( ColumnTypes... ) > rowCallback ){
while( this->nextRow() ){
int column = 0;
rowCallback( this->getColumn< ColumnTypes >( column++ )... );
// unreliable increment ^
}
}
template< typename T >
T SQLStatement::getColumn( const int columnIdx ){}
template<>
inline int SQLStatement::getColumn< int >( const int columnIdx ){
return sql_library_column_int( this->nativeHandle, columnIdx );
}
// Other getColumn specializations here...