regex_replace return 错误的字符串

regex_replace return wrong string

我尝试做一点 Mustache 渲染器:

std::string Mustache::render(const std::string& tmplt,const std::map<std::string,std::string>& context)
{
   std::string result = tmplt;
   for(std::map<std::string,std::string>::const_iterator it=context.begin(); it!=context.end(); ++it)
   {
      std::regex reg("({{"+it->first+"}})");
      result = std::regex_replace(result,reg,std::string(it->second));
   }

    return result;
}

我用以下代码测试了这段代码:

std::map<std::string, std::string> context;

context["test"] = "render-test";

std::cout <<  Mustache::render("It's a simple {{test}}");

但是returns

It's a simple {{test}}

而不是

It's a simple render-test

你看出哪里不对了吗?

谢谢

尝试

std::cout <<  Mustache::render("It's a simple {{test}}", context);

而不是

std::cout <<  Mustache::render("It's a simple {{test}}");