http://stackoverflow.com/questions/20516773/stdunique-lockstdmutex-or-stdlock-guardstdmutex The difference is that you can lock and unlock a std::unique_lock. std::lock_guard will be locked only once on construction and unlocked on destruction. So fo…
huffman coding, greedy algorithm. std::priority_queue, std::partition, when i use the three commented lines, excution time increase to 15ms from 0ms, due to worse locality? thanks to http://acm.hdu.edu.cn/discuss/problem/post/reply.php?action=support…
下面为测试代码: 1.创建 std::vector< std::vector<string> > vc2; 2.初始化 std::vector<string> vc; vc.push_back("v11"); vc.push_back("v12"); vc.push_back("v13"); std::vector<string> v2; v2.push_back("v21");…
从最基础的了解,std::bind和std::function /* * File: main.cpp * Author: Vicky.H * Email: eclipser@163.com */ #include <iostream> #include <functional> #include <typeinfo> #include <string.h> int add1(int i, int j, int k) { return i + j + k;…
LeetCode 26 Remove Duplicates from Sorted Array [Array/std::distance/std::unique] <c++> 给出排序好的一维数组,删除其中重复元素,返回删除后数组长度,要求不另开内存空间. C++ 很简单的题目,但是第一发RE了,找了很久问题出在哪.最后单步调试发现vector.size()返回值是unsigned型的.unsigned型和int型数据运算结果还是unsigned型的.这就导致当数组为空时,nums.size(…
错误显示:没有与这些操作数匹配的 "<<" 运算符       操作数类型为:  std::ostream << std::string 错误改正:要在头文件中加入<string>头函数…
MATLAB部分: xmap = repmat( linspace( -regionW/2, regionW/2, regionW), regionH, 1 );%linspace [x1,x2,N] 等差数列 ymap = repmat( linspace( -regionH/2, regionH/2, regionH)', 1, regionW); %转置 %compute the angle of the vector p1-->p2 vecp1p2 = labelData(2,:) -…
C++多线程编程中通常会对共享的数据进行写保护,以防止多线程在对共享数据成员进行读写时造成资源争抢导致程序出现未定义的行为.通常的做法是在修改共享数据成员的时候进行加锁--mutex.在使用锁的时候通常是在对共享数据进行修改之前进行lock操作,在写完之后再进行unlock操作,进场会出现由于疏忽导致由于lock之后在离开共享成员操作区域时忘记unlock,导致死锁. 针对以上的问题,C++11中引入了std::unique_lock与std::lock_guard两种数据结构.通过对lock和…
c++二分查找的用法 主要是 std::binary_serach,  std::upper_bound以及std::lower_bound 的用法,示例如下: std::vector<int> vtr; ; i < ; i++) { == ) vtr.push_back(i); } auto find = [&](int num){ return std::binary_search(vtr.begin(), vtr.end(), num); //二分查找num是否存在 };…
上一讲<C++11 并发指南四(<future> 详解二 std::packaged_task 介绍)>主要介绍了 <future> 头文件中的 std::packaged_task 类,本文主要介绍 std::future,std::shared_future 以及 std::future_error,另外还会介绍 <future> 头文件中的 std::async,std::future_category 函数以及相关枚举类型. std::future…