- 浏览: 253413 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (152)
- Qt (21)
- C++ (10)
- javascript (8)
- linux (8)
- RTC (1)
- JNI (1)
- Qt 图形 (1)
- Mac Bootcamp (1)
- node.js (3)
- Windows SDK 7.1 (1)
- VS2010 (2)
- linux Tcl 脚本语言 (0)
- Mac (1)
- Clucene VS2013 (1)
- VisualStudio (1)
- golang (11)
- postgresql (5)
- SVN (1)
- VS (2)
- 微信开发 (8)
- html5 (1)
- Win7 (1)
- Office (1)
- redis (1)
- Bootstrap (1)
- nginx (2)
- docker (1)
- xorm (3)
- blender (2)
- linux ec2 (1)
- aws (1)
- 七牛云 (1)
- css (5)
- h2 (1)
- react (2)
- java (2)
- html (2)
- eclipse (1)
- java swing (1)
- webpack (1)
- mysql (5)
- VS2017 (1)
- 网站 (1)
- tomcat spring (1)
- Ant (2)
- sql (1)
- 其它 (1)
- Win10 (1)
- R (1)
- git (1)
- Windows (1)
- ubuntu (2)
- python (3)
- win 11 (1)
- quasar (1)
最新评论
在我锲而不舍的努力下,std::map由value反求key的模板函数终于出炉了:使用时一定要把map的具现类型也传进去,想琢磨去掉这个模板参数的同学不信就试试,一定会死的很难看的。
#include <algorithm>
template <class K, class V>
class value_equals//本模板类来自于<The C++ Standard Library>
{
private:
V value;
public:
// constructor (initialize value to compare with)
value_equals (const V& v) : value(v) {}
// comparison
bool operator() (pair<const K, V> elem)
{
return elem.second == value;
}
};
template <typename K,typename V,typename Map>
K FindKeyByValue(const Map& m, const V& v)//本模板函数由johnsmith9th原创,引用请注明来自于http://johnsmith9th.iteye.com
{
typename Map::const_iterator pos = find_if(m.begin(),m.end(), value_equals<K,V>(v));
if (pos != m.end())
{
return pos->first;
}
K defaultKeyValue;
return defaultKeyValue;
}
#include <algorithm>
template <class K, class V>
class value_equals//本模板类来自于<The C++ Standard Library>
{
private:
V value;
public:
// constructor (initialize value to compare with)
value_equals (const V& v) : value(v) {}
// comparison
bool operator() (pair<const K, V> elem)
{
return elem.second == value;
}
};
template <typename K,typename V,typename Map>
K FindKeyByValue(const Map& m, const V& v)//本模板函数由johnsmith9th原创,引用请注明来自于http://johnsmith9th.iteye.com
{
typename Map::const_iterator pos = find_if(m.begin(),m.end(), value_equals<K,V>(v));
if (pos != m.end())
{
return pos->first;
}
K defaultKeyValue;
return defaultKeyValue;
}
发表评论
-
运行时PyImport_ImportModule或者py::import调用失败, error_already_set
2023-03-24 20:29 216解决方案1: 拷贝python或conda目录下的DLLs和 ... -
返回满足条件的std::vector的子集
2022-01-27 16:39 323c++ 11: std::vector<float& ... -
Qt开发磁盘空间查看器
2021-09-09 10:30 0int main(int argc, char **argv ... -
error LNK2001: unresolved external symbol std::basic_ostream
2021-07-13 17:10 341std标准库都无法链接的话,说明编译运行时不一致。 最后排查是 ... -
C2504: base class undefined
2018-02-28 10:39 1034I found the compiling error &q ... -
Qt Creator配置vs2010编译器和调试器
2014-10-14 00:20 9534(本文系原创,转载请 ... -
CMD_BEGIN(...) & CMD_COMMIT()
2014-04-17 11:43 0#include <QWidget> #inclu ... -
[转载]不定参数个数的C函数
2014-04-15 13:06 0原文地址:http://gqlyxg198 ... -
用typeof和decltype为宏(macro)传递变量的类型信息
2014-04-15 11:56 0#ifdef WIN32 #define typeof dec ... -
fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
2014-04-15 11:42 2440VC编译报这个错误,设工程的两个配置来解决该问题:一个是取消L ... -
typedef 类型的头文件声明
2014-01-22 13:10 1227结论是编译器不支持,不要浪费时间来做这个事情,老老实实地inc ... -
特化与multiple definition及
2013-10-11 18:44 2258程序员已经习惯于将模板类的实现放到头文件里,但是有一些特化类或 ... -
QGraphicsWidget的geometry和boundingRect是什么关系?
2012-12-25 17:08 1519QGraphicsWidget的boundingRect的概念 ...
相关推荐
std::map<std::string, std::map<std::string, std::string>> _data; public: int32_t readInteger(std::string section, std::string key, int32_t defaultValue); float readFloat(std::string section, std:...
flyfish 测试所需头文件 #include #include #include <map> #include 初始 std::map<int> t;... t.insert(std::make_pair(1, "a"));... t.insert(std::make_pair(2, "b"));...根据key 找 value std::string s = "
c++ 无序map 及使用,vs可以编译。 tsl::ordered_map, int> map = { {'d', 1}, {'a', 2}, {'g', 3} };... std::cout << "{" << key_value.first , " << key_value.second << "}" << std::endl; }
A Json object represents any JSON value: null, bool, number (int or double), string (std::string), array (std::vector), or object (std::map). Json objects act like values. They can be assigned, ...
map是STL的关联式容器,以key-value的形式存储,以红黑树(平衡二叉查找树)作为底层数据结构,对数据有自动排序的功能。 命名空间为std,所属头文件<map> 注意:不是<map> 二:常用操作 容量: a.map中实际数据的数据...
c#原始码转Java原始码的json11 json11是用于C ++ 11的微型JSON库,提供JSON解析和序列化。 该库提供的核心对象是json11 :: Json。 Json对象代表任何JSON值:null,bool,数字...还有一些隐式构造函数,可将标准类型
(用作 std::map 的 key_type 是更进一步的要求,本文从略)。 换言之,你的 String 能让以下代码编译运行通过,并且没有内存方面的错误。 代码如下:void foo(String x) { } void bar(const String& x) { } ...
* Map的特点: 1、存储Key-value对 * 2、支持快速查找,查找的复杂度基本是Log(N) * 3、快速插入,快速删除,快速修改记 * /************************************************************************/ #include #...
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"] " 自动关闭补全窗口 au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif set completeopt=menuone,menu,longest set nocp "} "}}...
C++实现仅有孩子节点的红黑树 在旋转时用栈存储叔叔父亲祖先等等。...using namespace std; #define RefValue -1e8 #define red 0 #define black 1 template struct RBNode { bool color; K key; E data; RBN
Table of Contents Header Files The #define Guard Header File Dependencies Inline Functions The -inl.h Files Function Parameter Ordering Names and Order of Includes Scoping Namespaces Nested Classes ...
Default value of the SkinProvider.MakeSkinMenu property was changed to False (all projects must be checked and updated if required) * Solved problems in Magnifier and AlphaControls color dialog that...
CHAPTER 7 PASSING BY REFERENCE OR VALUE CHAPTER 8 NUMERICAL, LOGICAL, AND STRING DATA CHAPTER 9 SPECIAL DATA TYPES Index Microsoft Codeview and Utilities User's Guide Table of Contents Introduction ...