Effective Modern C++的笔记(7)

按有用程度 按页码先后 最新笔记

  • Cynosure (我是一只橘)

    Things to Remember Item 8 • Prefer nullptr to 0 and NULL. • Avoid overloading on integral and pointer types. Item 9: Prefer alias declarations to typedef s • typedefs don’t support templatization, but alias declarations do. • Alias templates avoid the “::type” suffix and, in templates, the “typename” prefix often required to refer to typedefs. • C++14 offers alias templates ...

    2018-08-05 12:46:28   1人喜欢

  • meerkat

    本章着重解释了auto在何时应该被使用,在何时不应该被使用; auto的好处是: 1. 变量初始化不会遗忘; 2. 定义变量更加简单; 3. 有时还可以避免因为错误的类型定义导致的隐式转换带来的性能问题; 例如: 在我自己的机器上, std::unordered_map a; for (const auto& p : a) { // Do something.... } 比 for (const std::pair& p : a) { // Do something .... } Benchmar...

    2020-02-15 16:42:11

  • meerkat

    auto a = {1, 2, 3}; 类型推断a为std::initializer_list。 auto b{1}; 类型推断b 为int。 template void templated_fn(T) {} templated_fn({1, 2, 3}); // compiler error! "{1, 2, 3}" is not an expression, it has no type, and so T cannot be deduced 这个auto type deduction和template type deduction主要的区别; int x是一个左值,(x)也是一个左值,但是前者decltype是int,后者是int&;

    2020-02-14 11:27:51

  • Cynosure (我是一只橘)

    Errata: http://www.aristeia.com/BookErrata/emc++-errata.html Item2 int x1 = 27; int x2(27); int x3 = { 27 }; int x4{ 27 }; auto x1 = 27; // type is int, value is 27 auto x2(27); // ditto auto x3 = { 27 }; // type is std::initializer_list,value is { 27 } auto x4{ 27 }; // ditto 。 Item 5: Prefer auto to explicit type declarations auto variables have their type deduced from their initializer...

    2018-08-04 10:35:45

  • Nightash

    这里的本质区别是: // unique_ptr template unique_ptr 的 Deleter 在模板具象化的时候生成 而 获得具体代理类 T的 complete 型别 则是在 unique_ptr 构造函数获得(动态) 这 2个时间点不一定是相同的 典型的对于ImplPattern unique_ptr 使用者必须保证 Deleter 在 具体 unique_ptr 构造函数所在的代码内 出现实现 否则 编译器对于 对于 delete incomplete type; 将生成 默认trivial destruc...

    2015-01-05 15:39:26

  • Nightash

    for loop const std::pair& 问题 gcc 跟 vs2012都有相同问题 编译能通过

    2014-12-31 15:31:16

  • Nightash

    T DirectMapping(expr) { // 直接映射 // expr 就是 T } template void f(ParamType param) { ... } f(expr); switch( ParamType ) { case Param is normal_ref: { if(expr is ref) { // ignore expr refness } DirectMapping(expr); } break; case Param is normal_pointer: { if( expr is array or func ) { //decay to pointer( type_pointer or function_pointer) } if(expr is pointer) { // ignore expr poin...

    2014-12-30 15:15:43

笔记是你写在书页留白边上的内容;是你阅读中的批注、摘抄及随感。

笔记必须是自己所写,不欢迎转载。摘抄原文的部分应该进行特殊标明。

Effective Modern C++

>Effective Modern C++