c++ quiz
摘要:#include <string> #include <iostream> using namespace std; #define FMT_EXPAND(args) args #define FMT_CONCAT(a, b) a##b #define FMT_ADD_ARG_NAME(type,
阅读全文
posted @
2017-03-27 08:44
abelian
阅读(149)
推荐(0)
enable_share_from_this
摘要:在什么情况下要使类A继承enable_share_from_this? 使用场合:当类A被share_ptr管理,且在类A的成员函数里需要把当前类对象作为参数传给其他函数时,就需要传递一个指向自身的share_ptr. 类A继承enable_share_from_this,然后通过share_fro
阅读全文
posted @
2017-02-03 11:11
abelian
阅读(320)
推荐(0)
index 可变模板展开
摘要:https://www.zhihu.com/question/51253466 #include <iostream> #include <fstream> #include <memory> #include <iterator> #include <type_traits> #include <
阅读全文
posted @
2017-01-17 09:52
abelian
阅读(227)
推荐(0)
template template parameter
摘要:#include <iostream> using namespace std; template<typename T> class A { }; template<typename T> class B { }; template<typename T, template<typename >
阅读全文
posted @
2017-01-16 19:26
abelian
阅读(147)
推荐(0)
sfinae
摘要:https://www.zhihu.com/question/54713079/answer/140746689 #include <iostream> using namespace std; template<class T> struct foo { using type = T; }; te
阅读全文
posted @
2017-01-15 11:14
abelian
阅读(178)
推荐(0)
variadic variadic template template parameters
摘要:http://stackoverflow.com/questions/38611823/variadic-variadic-template-template-parameters-parameters variadic variadic template template parameters i
阅读全文
posted @
2017-01-11 14:26
abelian
阅读(127)
推荐(0)
common
摘要:lexical_cast 提供string2int, int2string, #define(...) 可变宏:…和__VA_ARGS__ 宏定义中参数列表的最后一个参数为省略号(三个英文句号,省略号只能代替最后参数)。这样,预定义宏__VA_ARGS__就可以被用在替换部分中,以表明省略号代码什么
阅读全文
posted @
2017-01-09 12:41
abelian
阅读(172)
推荐(0)
延迟构造
摘要:template<typename T,typename P> struct type_para { typedef T type; P p; ..... }; template<typename T,typename ...AK> auto create(AK&&... ak) { return
阅读全文
posted @
2017-01-08 09:33
abelian
阅读(153)
推荐(0)
如果存在的话就调用
摘要:一,判断在类中某个函数(也可以是变量或类型)是否存在 template<typename T> struct xxxx_detector { template<typename P,void (P::*)(void)> struct detector{}; template<typename P>
阅读全文
posted @
2017-01-08 09:31
abelian
阅读(147)
推荐(0)
判断在类中某个函数(也可以是变量或类型)是否存在
摘要:一,判断在类中某个函数(也可以是变量或类型)是否存在 template<typename T> struct xxxx_detector { template<typename P,void (P::*)(void)> struct detector{}; template<typename P>
阅读全文
posted @
2017-01-08 09:22
abelian
阅读(259)
推荐(0)
tuple解包给类的构造函数
摘要:首先我们的第一步当然是将tuple解包。tuple提供了一个get函数来获取第N个元素。例如: get<1>(make_tuple(...)); 要将一个tuple全部拆解,就可以使用通过多次调用这个函数来进行解析,例如: auto tup = make_tuple(..........); fun
阅读全文
posted @
2017-01-08 09:06
abelian
阅读(358)
推荐(0)
C++14使用std::integer_sequence展开tuple作为函数的参数
摘要:元组是一种长度固定的允许有不同类型元素的集合,根据元素的个数不同又分别称作一元组、二元组、三元组等。C++11中标准库增加了一个叫std::tuple的类模板,用于表示元组。 下面的代码演示了使用C++创建一个三元组。 auto tuple = std::make_tuple(1, 'A', "te
阅读全文
posted @
2017-01-08 01:34
abelian
阅读(2099)
推荐(0)
可变参数模板
摘要:一、基本语法 声明一个带有可变参数个数的模板的语法如下所示: template<typename ...Element> class tuple; tuple<int, string> a; // use it like this 在模板参数 Element 左边出现省略号 ... ,就是表示 El
阅读全文
posted @
2017-01-06 10:15
abelian
阅读(884)
推荐(0)
模板特化类型
摘要:C++的模板及模板特化的几种特化:方式1特化:template<class T>class Compare{public: static bool IsEqual(const T& lh, const T& rh) { return lh == rh; }};template<>class Comp
阅读全文
posted @
2017-01-05 19:29
abelian
阅读(232)
推荐(0)
printf 整数类型都用 uint8_t
摘要:#include <iostream> #include <string> #include <tuple> #include <utility> #include <array> #include <string> template<char...> struct STRING { }; temp
阅读全文
posted @
2017-01-04 14:31
abelian
阅读(1278)
推荐(0)
policy
摘要:template <class Apolicy> class Host { Apolicy direct_policy_use; Apolicy <SomeInternalType> InternalClone; // Problem 1: Can't do this }; template <cl
阅读全文
posted @
2017-01-04 12:41
abelian
阅读(530)
推荐(0)
类模板参数
摘要:实际上有三种类型模板参数:类型模板参数、无类型模板参数和模板模板参数(以模板作为模板的参数)。 1、类型模板参数 类型模板参数是我们使用模板的主要目的。我们可以定义多个类型模板参数: template<typename T,typename Container> class Grid {...} 同
阅读全文
posted @
2016-12-31 14:00
abelian
阅读(458)
推荐(0)
future
摘要:/*T ->return type, E -> error type, D -> parameter type */ template<typename T, typename E, typename D = void> using result_t = typename internal::res
阅读全文
posted @
2016-11-10 15:11
abelian
阅读(106)
推荐(0)
shared_ptr 线程安全
摘要:Then what's really happening is TWO different sections of memory are being allocated. It's done at one time, but it's two "logical" blocks. One is the
阅读全文
posted @
2016-11-08 18:01
abelian
阅读(229)
推荐(0)
参数自然匹配
摘要:#include <type_traits> #include <utility> struct A {}; struct B {}; struct C {}; void func(A, const C&, B) {} template<typename func_return_type, type
阅读全文
posted @
2016-11-06 13:10
abelian
阅读(144)
推荐(0)