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}});
}
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}});
}
相关文章推荐
- Cannot update paths and switch to branch 'snapshot_mixuse' at the same time.
- Cannot update paths and switch to branch at the same time(转)
- clone 远程分支 Cannot update paths and switch to branch 'dev' at the same time. Did you intend to checko
- fatal: Cannot update paths and switch to branch 'gitlab' at the same time.
- Using MERGE in SQL Server to insert, update and delete at the same time
- how to play music and record from the mic at the same time?
- Cannot update paths and switch to branch at the same time
- Cannot update paths and switch to branch at the same time
- git checkout -b时fatal: Cannot update paths and switch to branch '' at the same time.解决方案
- Git问题:Cannot update paths and switch to branch 'dev' at the same time.
- fatal: Cannot update paths and switch to branch 'master' at the same time.
- mysqld_safe Can't log to error log and syslog at the same time.
- Could I use NEON and VFP at the same time in my application?
- full backup and log backup can happen at the same time
- only one software management tool is allowed to run at the same time
- Read and write a FileStream at the same time
- Setup 64-bit Windows Server for Running ASP.NET 1.1 and ASP.NET 2.0 at the Same Time
- Setup 64-bit Windows Server for Running ASP.NET 1.1 and ASP.NET 2.0 at the Same Time
- Running PHP(Apache) and ASP.NET(IIS) at port 80 at the same time
- How can a database be in-memory and durable at the same time?