相关疑难解决方法(0)

C++编译时函数执行

我的代码中有字符串标记,它们被转换为数字并用于在标记值结构中搜索值.

我有这样的事情:

void foo()
{
    type value = search("SomeTag");
}
Run Code Online (Sandbox Code Playgroud)

搜索定义如下:

type search(const char* tag)
{
    return internal_search(toNumber(tag));
}
Run Code Online (Sandbox Code Playgroud)

因为所有时间标记在编译时都是常量,所以我想删除将标记转换为搜索函数中的数字的调用.我知道可以在编译时使用模板(http://en.wikipedia.org/wiki/Compile_time_function_execution)执行一些简单的函数,但我不知道如何迭代空终止字符串并保留中间值在模板中.你能给出一个简单的样本来迭代一个空终止的字符串,并在一个公共变量中添加字符吗?

c++ template-meta-programming

12
推荐指数
2
解决办法
5050
查看次数

标签 统计

c++ ×1

template-meta-programming ×1