- 博客(88)
- 资源 (4)
- 收藏
- 关注
原创 C++模仿python的装饰器功能
C++固有语法限制,导致能模仿功能,但是无法模仿语法function<int (int)> f = [](int x){return x;};DECORATOR(f, pre, post)被装饰的函数必须使用function<。。。>类型,然后在函数定义后面,使用DECORATOR宏进行装饰。如果这个不可接受的话,下面内容也就不用看啦。装饰函数的示例://调用前装饰,要能接受被装饰函数的所有参数,//可以传拷贝、&、const &,取决于是
2021-04-24 23:04:20
964
原创 C++实现flatten:扁平化容器的容器的容器。。。
zip、map/reduce、flatten是比较有意思的通用算法。zip在boost::iterator里有了,map/reduce是用transfom、accumulate、inner_product实现的。flatten就没找到了,那就造个吧:template<typename T, typename C>constexpr void do_flatten(const C & c, T & ret) { for (const auto & x
2021-03-15 22:50:54
1112
原创 JSON for Modern C++的dump函数的一个小修改:纯数值内容放在同一行
对于[1,2,3...]这样的纯数值json,使用dump(4)输出会占用非常多的行:[ 1, 2, 3,。。。]我个人喜欢对这样的纯数值,只用一行,所以小改了一下源代码:void dump(const BasicJsonType& val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigne
2021-01-16 10:31:31
670
原创 记录:C++ 编译期静态反射
如何优雅地实现 C++ 编译期静态反射https://mp.weixin.qq.com/s/y1GULGBR-ktn-2N1fJ8CDw文章讲得不错。提取一下重点:使用T t = {。。。};语法可以提取出结构体T的成员数量。原理:当{。。。}里面给的初始化值个数小于等于T的成员数量时,初始化语法成立。 如果初始化值个数超过T的成员数量时,初始化语法不成立,会编译报错。据此,使用SFINAE机制就可以获得成员数量啦。不过,这个文章还不是最优解。BOOST1.75刚...
2021-01-04 11:47:39
1143
原创 C++实现enum转字符串,支持enum的指定值语法
C/C++的enum,无法直接转换到字符串,比如 enum FRUIT {apple, grape=10, orange};,永远只有0、10、11,无法得到能直观理解的“appl”、“grape”、“orange”了。Java语言就能在打印枚举值时打印出字符串。cout << FRUIT(10) 我们希望输出的是grape,而不是10直到C++2020标准都出台了,也没听说C/C++给出标准解决方案。而这个需求其实一直非常强烈。常见的解决方案:1)做一个class,它有一.
2020-12-05 11:23:38
3796
原创 C++安全的窄转换narrow_cast的新语法实现
//利用了C++新语法:构造自动推导模板类型template<typename SOURCE, typename = std::enable_if_t<std::is_arithmetic<SOURCE>::value>> struct narrow_cast{ SOURCE source; narrow_cast(SOURCE s...
2019-12-24 11:21:46
2320
1
原创 windows下mingw32使用tcmalloc
使用的mingw: i686-8.1.0-release-posix-dwarf-rt_v6-rev0 tcmalloc: gperftools2.7覆盖gperftools2.5 msys2: 20180531,这个看起来不重要1)github上,官方的gperftools已经是2.7,但是没有带configure文件,github上还有...
2019-12-23 11:39:28
784
原创 boost::coroutine2用mingw 32编译,出forced_unwind异常的解决
一句话,使用dwarf版本,不要用sjlj版本。
2019-02-23 15:08:09
451
原创 用正则判断配对的“()”?没问题,一行搞定
boost::regex 好像要1.5x吧,扩展perl语法(?(DEFINE)(?<parentheses>(?>\ ((?:[^()'"]|(?&parentheses))*\ ))))\ ( 、 \ )间的空格自己去掉一下。以后直接用(?&parentheses)就行。什么?''和“”里的()怎么办?(?(DEFINE)(?<cha...
2018-12-18 10:19:14
334
原创 C99的指定初始化转化为C89?用(a|e)?bnf实现吧,写个玩玩
struct MemberInfo{ string type; string name; deque arrSizes;}; struct InitValue{ string value; vector sub; string name;// TYPE type; Ini
2014-06-13 22:46:21
1433
1
原创 正则是如何判断有重复/由不重复的数字组成的串的。
源自这里:http://bbs.youkuaiyun.com/topics/390804087(?!.*?(\d).*?\1.*?$)\d+
2014-06-05 21:07:39
7619
原创 编译宏控过滤和宏替换工具,还是放出来吧,也许对一些人有点用。
http://download.youkuaiyun.com/detail/taodm/5075958
2013-02-20 22:50:28
1765
原创 boost::preprocess的神秘魔法的实现细节:BOOST_PP_SEQ_SIZE(SEQ)
BOOST_PP_SEQ_SIZE还可以展示一下,BEGIN BOOST_PP_SEQ_FOLD_LEFT(SUB_S, 22, SEQ) == 10 END直接生产了2.6M的log过程。# define SEQ (4)(1)(5)(2) 开始处理代码:BOOST_PP_SEQ_SIZE(SEQ)//--------------------------------------
2013-01-30 20:36:15
2764
5
原创 最小公约数,python怎么写,C++(2011/boost)就也怎么写
http://lionelliu.com/?p=1729def gcd(a, b): whileb: a, b= b, a%b returna int gcd(int a, int b){ while (b) { tie(a, b) = make_pair(b, a % b)
2013-01-30 20:23:27
1062
原创 最近用了一把boost::range,哎,真方便。(水帖)
难怪有老外大牛写文章“iterator must go"。stl是该彻底重写了。嗯,我的C++代码越来越向python代码靠拢了。
2012-07-29 22:28:23
2539
2
原创 《C++程序设计原理与实践》书评
<br /> 在2周内,以1目10行的速度读过了这本书。小小书评如下:<br /> 这是一本主要面向初学者的极好的教材。<br /> 在我看过的编程书籍中,这是第二本适合于完全无编程经验的初学者的入门书籍(前面一本叫《C语言解析教程》)。但是,这本书目前还没听说有配套的习题、提问解答,所以它也还不能列为完全自学书籍。<br /> 这是我见过的唯一一本不以语法为主线索的教材,它是以实践需要来逐次引入相关语法的。对于初学者,最重要的是建立自信。若以语法为主线,也许教材已经看了大半,可还没
2010-08-27 09:48:00
4649
5
原创 今天被挑战自己的基本功了,结果狂汗!
<br />unsigned long aaa;<br />istringstream in("-1");<br />in >> aaa;<br />cout << aaa;<br />sscanf("-1", "%ul", &aaa);<br />cout << aaa;<br />汗!狂汗!<br />起因由此:<br />http://topic.youkuaiyun.com/u/20100706/10/70598abf-6f50-4793-b22e-7b8b533a7e62.html?see
2010-07-07 09:19:00
1419
3
原创 持续关注云风的写不出书,和某些的人的写书天下第一
额外针对初学者说一句:绝对入门不要选错书,即使你是富二代,不差钱。买书前,看看书评是很重要。国外书籍,看亚马逊。国内书籍,请多关心csdn。
2010-02-05 15:23:00
1687
3
原创 boost xpressive库,介于正则和bnf库之间的混血。显示c/c++代码注释部分。
#include #include using namespace boost::xpressive;sregex e_string = as_xpr(") >> *((as_xpr(//) >> _) | ~(boost::xpressive::set = //, ")) >> ";sregex e_char = as_xpr(/) >> *((as
2009-06-26 15:28:00
1834
原创 wxString在gcc4.4下的bug
wx的string.h line 259 static const size_t npos;在gcc3X下,会启用外部编链,获得正确的-1.在gcc4.4下,是放弃外部编链,当0处理了。结果,char *无法转换为wxString。解决1 wxString(s, strlen(s)) 2 wxString::Format("%s", s); 3
2009-04-13 22:29:00
757
原创 Loki库读解 STATIC_CHECK扩展:可放在任何地方的STATIC_CHECK,编译期打印出类型的大小
在Loki的static_check.h中不只有STATIC_CHECK,还有一个STATIC_SIZE_ASSERT。以前一直忽略了这个STATIC_SIZE_ASSERT,现在突然发现,它是可以写在代码的几乎任何地方的,而STATIC_CHECK只能放在函数中。模仿STATIC_SIZE_ASSERT也实现一个可放在任何地方的STATIC_CHECK并不困难。Loki作这样的选择,我想
2004-04-15 17:39:00
2557
1
原创 Loki库读解-扩展TypeList:Typelist生成器、MaxSizeOf
Loki中的TYPELIST_**宏还是太难用了,因为无法支持不定参数。借鉴于BOOST中的Tuple的想法,实现了这个Typelist_Maker:template class T6 = NullType, class T7 = NullType, class T8 = NullType, class T9 = NullType, class T10 = Null
2004-04-08 18:51:00
1978
原创 CUJ:高效使用标准库:显式函数模板参数申明与STL
Effective Standard C++ Library: Explicit Function Template Argument Specification and STL A New Language Feature and Its Impact on Old Programming Techniques Klaus Kreft and Angelika Langerh
2003-05-18 11:01:00
4551
原创 CUJ:高效使用标准库:STL中的unary predicate
Effective Standard C++ Library: Unary Predicates in the STL Klaus Kreft and Angelika Langerhttp://www.cuj.com/experts/1904/toc.htm?topic=experts 标准运行库中的几个泛型算法在运行时使用了一元判定式(unary pr
2003-05-13 11:18:00
3850
原创 CUJ:高效使用标准库:for_each() vs. transform()
Effective Standard C++ Library: for_each() vs. transform()Klaus Kreft and Angelika Langerhttp://www.cuj.com/experts/1902/langer.htm?topic=experts Note: Article updated on January 5, 200
2003-05-08 12:03:00
3092
原创 CUJ:高效使用标准库:set的iterator是mutable的还是immutable的?
Effective Standard C++ Library: Are Set Iterators Mutable or Immutable? Portability Issues in Using the Standard Library Klaus Kreft and Angelika Langerhttp://www.cuj.com/experts/1810/kreft.
2003-05-04 00:15:00
2571
原创 CUJ:标准库:bitset和bit vector
The Standard Librarian: Bitsets and Bit VectorsMatt Austernhttp://www.cuj.com/experts/1905/austern.htm?topic=experts在 C++里,你能如愿地玩弄位元,而且甚至不用到宏。--------------------------------------------------
2003-05-01 11:17:00
3414
2
原创 CUJ:标准库:容纳指针的容器
The Standard Librarian: I/O and Function Objects: Containers of PointersMatthew Austernhttp://www.cuj.com/experts/1910/austern.htm?topic=experts--------------------------------------------------
2003-05-01 10:56:00
2650
2
原创 CUJ:标准库:容纳不完全类型的容器
The Standard Librarian: Containers of Incomplete TypesMatt Austernhttp://www.cuj.com/experts/2002/austern.htm?topic=experts-----------------------------------------------------------------------
2003-04-30 11:11:00
2048
原创 CUJ:标准库:定义iterator和const iterator
The Standard Librarian: Defining Iterators and Const IteratorsMatt Austernhttp://www.cuj.com/experts/1901/austern.htm?topic=experts---------------------------------------------------------------
2003-04-23 23:22:00
4573
1
原创 CUJ:标准库:基于文件的容器
The Standard Librarian: File-Based ContainersMatt Austernhttp://www.cuj.com/experts/1907/austern.htm?topic=experts--------------------------------------------------------------------------------
2003-04-21 09:00:00
2090
原创 CUJ:标准库:标准库中的搜索算法
The Standard Librarian: Searching in the Standard LibraryMatthew Austernhttp://www.cuj.com/experts/1911/austern.htm?topic=experts The genius as well as the oversights in the design of the Stan
2003-04-18 08:45:00
1979
原创 CUJ:标准库:标准库中的排序算法
The Standard Librarian: Sorting in the Standard LibraryMatthew Austernhttp://www.cuj.com/experts/1908/austern.htm?topic=experts-------------------------------------------------------------------
2003-04-16 16:32:00
2966
原创 CUJ:标准库:Allocator能做什么?
The Standard Librarian: What Are Allocators Good For?Matt Austernhttp://www.cuj.com/experts/1812/austern.htm?topic=experts------------------------------------------------------------------------
2003-04-14 09:11:00
2727
1
原创 CUJ:标准库:调试用的Allocator
The Standard Librarian :A Debugging AllocatorMatt Austernhttp://www.cuj.com/experts/1912/austern.htm?topic=experts--------------------------------------------------------------------------------
2003-04-02 08:57:00
3625
原创 CUJ:标准C++编程:虚函数与内联
标准C++编程:虚函数与内联Josée Lajoie and Stanley Lippman----------------------------------------------------------------------------------[This is the last installment of a column that was being published
2003-03-31 09:26:00
2558
原创 Effective STL Item 43:优先使用STL泛型算法以取代手写循环
STL泛型算法vs.手写的循环Scott Meyers准备进行优化?别那么急。Scott正试图让你相信库函数比你自己写的更好。------------------------------------------------------------------------------- [这篇文章源自一本即将出版的书。S. Meyers,Effective STL:50 Specif
2003-03-27 11:06:00
1396
原创 C++语言概念域检查
C++语言概念域检查Dr. Dobbs Journal June 2001出处:http://hyper.vcsun.org/HyperNews/rlingard/get/CS380f2002/sharing/201.html 使用模板进行编程的更佳实践。By Jeremy Siek and Andrew LumsdaineJeremy and Andrew work in
2003-03-27 10:54:00
1598
原创 CUJ:普及知识:typeint
普及知识: typeintStephen C. Dewhurst (WQ注:这是比Loki还令我震惊的东西,实在难以译好。先放出来让大家都震惊一下,以后我会修订的。)-------------------------------------------------------------------------------- 在最近的系列文章中,我们为 C++语言设计和实现
2003-03-15 10:17:00
1629
原创 Effective STL: Item 44:优先使用与泛型算法同名的成员函数
Item 44:优先使用与泛型算法同名的成员函数一些容器拥有和STL泛型算法同名的成员函数。关联容器提供count()、find()、lower_bound()、upper_bound(),和equal_range(),而list提供了remove()、remove_if()、unique()、sort()、merge(),和reverse()。这样做有两个理由。首先,成员函数更快。其次
2003-03-11 09:35:00
1274
编译宏控过滤和宏替换工具stedit1.2.5pro
2013-02-20
统计函数平均长度和最大长度
2009-06-16
统计函数平均长度和最大长度
2009-06-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人