循环typedef

Joo*_*kia 2 c++ templates

我有一个无聊的功能来运行,我想循环它以节省这个时间(我有所有的数据),但它需要类型.有没有办法制作一个类型的数组,或有一些完成时间的事情来做到这一点?(如果它有帮助,我有3种类型,并希望针对所有类型运行所有类型的方法).

fprintf(stdout, "Testing UTF-32...\n");
testUTF<uint32_t, uint32_t>(&testEncs[0], &testEncs[0]);
testUTF<uint32_t, uint16_t>(&testEncs[0], &testEncs[1]);
testUTF<uint32_t, uint8_t> (&testEncs[0], &testEncs[2]);

fprintf(stdout, "Testing UTF-16...\n");
testUTF<uint16_t, uint32_t>(&testEncs[1], &testEncs[0]);
testUTF<uint16_t, uint16_t>(&testEncs[1], &testEncs[1]);
testUTF<uint16_t, uint8_t> (&testEncs[1], &testEncs[2]);

fprintf(stdout, "Testing UTF-8...\n");
testUTF<uint8_t,  uint32_t>(&testEncs[2], &testEncs[0]);
testUTF<uint8_t,  uint16_t>(&testEncs[2], &testEncs[1]);
testUTF<uint8_t,  uint8_t> (&testEncs[2], &testEncs[2]);
Run Code Online (Sandbox Code Playgroud)

Vau*_*ato 7

template <int I> struct UType;
template <> struct UType<0> { typedef uint32_t Type; };
template <> struct UType<1> { typedef uint16_t Type; };
template <> struct UType<2> { typedef uint8_t Type; };
static const int n_types = 3;

template <int A,int B>
struct Test {
  typedef typename UType<A>::Type AType;
  typedef typename UType<B>::Type BType;
  static void test()
  {
    testUTF<AType,BType>(&testEncs[A],&testEncs[B]);
    Test<A,B+1>::test();
  }
};

template <int A>
struct Test<A,n_types> {
  static void test() { Test<A+1,0>::test(); }
};

template <>
struct Test<n_types,0> {
  static void test() { }
};

void testAll()
{
  Test<0,0>::test();
}
Run Code Online (Sandbox Code Playgroud)