您的位置:首页 > 编程语言 > C语言/C++

C++0x : Inefficient way to perform trivial named args and default args at the same time

2011-12-02 12:14 645 查看
导语: 这既不是我的发明也不是我的发现,唯有能记下来的就是我自己独立想到这点。
This idea is not an invention nor a first discovery that can calledmy
own, it's simply to note it's somehow my work.

#include <cstdio>

#include <iostream>

#include <string>

#include <vector>

#include <map>

using namespace std;

typedef map
<string,int> OptionMap;

void foo(OptionMap const & options){

static OptionMap
defaultOpt =
{{"abc",123},{"def",456}};

OptionMap
x = options;

for(auto
par :
defaultOpt)

if (x.find(par.first)==x.end())x.insert(par);

for(auto
par :
x)

printf("OptionName = %s : Value = %d\n",par.first.c_str(),par.second);

}

int main(){

foo({{"def",567}});

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: