相关疑难解决方法(0)

用于循环模板参数/类型

我想为几个可能类的几种组合编写基准代码.如果我自己编写每个组合,它就变成了一个难以维护的混乱.因此,我正在寻找一种通过模板自动组合每种类型的方法,类似于以下伪代码:

for (typename HashFuction : Sha256, Sha512, Sa512_256, Sha3_256, Sha3_512) {
   for (typename KeyingWrapper : TwoPassKeyedHash, OnePassKeyedHash, PlainHash) {
      for (typename InstantiatedGetLeaf: GetLeaf<8>, GetLeaf<1024>) {
         for (typename algorithm : algA, algB, algC) {
            runAndTime<HashFunction,KeyingWrapper,
                       InstantiatedGetLeaf,algorithm>(someArgs);
         }
       }
    }
 }
Run Code Online (Sandbox Code Playgroud)

哪里Sha256,......,TwoPassKeyedHash......是类型.

我正在寻找的代码应该在功能上等同于以下内容:

runAndTime<Sha256,TwoPassKeyedHash,GetLeaf<8>,algA>(someArgs);
runAndTime<Sha256,TwoPassKeyedHash,GetLeaf<8>,algB>(someArgs);
runAndTime<Sha256,TwoPassKeyedHash,GetLeaf<8>,algC>(someArgs);

runAndTime<Sha256,TwoPassKeyedHash,GetLeaf<1024>,algA>(someArgs);
runAndTime<Sha256,TwoPassKeyedHash,GetLeaf<1024>,algB>(someArgs);
runAndTime<Sha256,TwoPassKeyedHash,GetLeaf<1024>,algC>(someArgs);

runAndTime<Sha256,OnePassKeyedHash,GetLeaf<8>,algA>(someArgs);
runAndTime<Sha256,OnePassKeyedHash,GetLeaf<8>,algB>(someArgs);
runAndTime<Sha256,OnePassKeyedHash,GetLeaf<8>,algC>(someArgs);

// And 99 further lines…
Run Code Online (Sandbox Code Playgroud)

在Peregring-lk的帮助下,我已经走到了尽头

#include <iostream>

template<typename Aux_type>
void test_helper()
{}

template<typename Aux_type, typename Head, typename... Tail>
void test_helper() {
   std::cout << Head::i;
   test_helper<Aux_type, …
Run Code Online (Sandbox Code Playgroud)

c++ templates metaprogramming

5
推荐指数
1
解决办法
1667
查看次数

标签 统计

c++ ×1

metaprogramming ×1

templates ×1