- 博客(17)
- 资源 (18)
- 收藏
- 关注
原创 aop之应用 时间记录器及日志
struct TimeElapsedAspect{ void Before(int i) { m_lastTime = m_t.elapsed(); } void After(int i) { std::cout << "time elapsed: " << m_t.elapsed() - m_lastTime << "ms" <<std::endl; }private:
2015-12-11 11:19:35 748
原创 c++ 面向切面变成 aop 通用模板
#ifndef AOP_h#define AOP_h#define HAS_MEMBER(member)\templatestruct has_member_##member\{\private:\ template static auto Check(int) -> decltype(std::declval().member(std::declval()...), std::tr
2015-12-11 11:17:12 1997
原创 c++11 计时器
#pragma once#includeusing namespace std;using namespace std::chrono;class Timer{public: Timer() : m_begin(high_resolution_clock::now()) {} void reset() { m_begin = high_resolution_clock::now(
2015-12-11 11:12:28 2821
原创 对象池 c++11
#ifndef COBJECTPOOL_H#define COBJECTPOOL_H#include #include #include #include const int maxObjectNum = 10;templateclass ObjectPool { template using Consturctor = std::function(Args...)>;pub
2015-12-10 21:11:17 1146
原创 使用函数包装器的 通用泛化的命令类
//#ifndef COMMCOMMAND_H#define COMMCOMMAND_H#include#includetemplate class CommCommand{private: std::function m_f;public: //接受可调用对象的函数包装器 template::value>::type> void Wrap(F &&f, Args &
2015-12-10 16:57:31 946
原创 std::forward 完美转发
templateinline auto FuncWrapper(Function &&f, Args &&...args){ return f(std::forward(args)...);}void hello(){ std::cout << "hello" << std::endl;}void hello1(std::string x){ std::cout << x
2015-12-10 16:23:01 642
原创 c++ final关键字
final关键字来限制类不能被继承,或者虚函数不能被重写。class A final {virtual void hehe() final;};如此,class A不能被其他类集成,hehe()函数也不能被重写
2015-12-08 14:19:06 2808
原创 c++ weak_ptr
weak_ptr是用来监视shared_ptr的,不会使引用计数增加。 std::shared_ptr t(new int(10)); std::weak_ptrwk(t); if(wk.expired()) std::cout<<"t is expired"<<std::endl; else std::cout
2015-12-08 13:40:26 468
原创 c++ tuple的基本操作
//create tuple std::tuple tp = std::make_tuple(2,2); int a,b; //get the value of tp std::tie(a,b) = tp; std::cout<<a+b<<std::endl; a = 0; //only get one value of tp std::tie(a,std::ignore) = t
2015-12-07 14:43:55 1858
原创 c++ lambda表达式捕获变量参数
[]不捕获任何变量[&]捕获外部作用域中所有变量,并作为引用在函数体重使用[=]捕获外部作用域中所有变量,并作为副本在函数体重使用[=,&foo]捕获外部作用域中所有变量,并作为副本在函数体重使用,对于foo按引用捕获[foo]当作副本捕获foo,不引入其他变量[this]捕获当前类中的this指针,让lambda表达式拥有和当前类成员函数同样的访问权限。如果已经使用了&或者=
2015-12-07 14:16:12 6486
原创 c++ std::bind 基本用法
#include void hello(int a){std::cout<<a<<std::endl;}void call_when(int x,const std::function &f){if(x == 0) f(x);} auto pt = std::bind(hello,std::placeholders::_1); call_when(0,pt);
2015-12-07 13:57:21 738
原创 c++ std::function作为参数传入函数
#include void hello(int a){std::cout<<a<<std::endl;}void call_when(int x,const std::function &f){if(x == 0) f(x);} call_when(0,hello);需要头文件functional,在std::function作为参数使用时,必须加con
2015-12-07 10:26:56 9103
原创 c++ 可调用对象
可调用对象分为如下几种:1 函数指针2 具有Operator()成员函数的类对象3 可被转换为函数指针的类对象4 类成员函数指针函数指针即函数的名字,直接调用即可具有operator成员函数的类对象,如下例所示:class foo{public: void operator()(void) {}};调用时:foo f;f();类的函数指
2015-12-07 10:16:56 550
原创 c++11,for,for each,std::for_each的应用
// cpp11exercise.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include void hello(int a){std::cout<<a<<std::endl;}int _tmain(int argc, _TCHAR* argv[]){ std::vector vv ; vv.
2015-12-04 19:36:22 12823
原创 在一个多线程系统中,主进程应该写什么?
在一个多线程的系统中,主线程应该不占资源,而且不应该结束。遵循此原则,在c++的系统中,用c++11的代码实现在主线程中等待主线程被唤醒,且不结束。#include #include std::mutex m_wt; std::unique_lock lk(m_wt); std::condition_variable wt;//在主线程结束之前 wt.wait(lk);
2015-12-02 10:52:13 1052
原创 c++ 并发系统访问 测试 调试方法/策略
如果在单核系统中没有错误,但是在多核系统或多处理器中出错,可能是竞争条件错误或者同步、内存顺序错误。测试实例的应用场景:1、在一个线程自身队列上调用push()或pop()来验证该队列工作基础级别2、在一个空队列上一个线程调用push(),另一个线程调用pop()3、在一个空队列上多个线程调用push()4、在一个满队列上多个线程调用push()5、在一个空队列上多个线程调
2015-12-02 10:32:58 567
线程池,c++11,跨平台,支持vs12,g++最新的编译器,高效
2015-12-04
Transact-SQL语句基础
2014-12-26
信息检索导论答案 introduction to information retrieval
2014-09-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人