#include <iostream>
# include <set>
#include <chrono>
#ifndef UNUSED
#define UNUSED(v) (void)(v)
#endif
typedef std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> time_point;
//void logg(const time_point& tp, std::string& name)
void logg(const time_point& tp, const std::string& name)
{
UNUSED(tp);
UNUSED(name);
std::cout << " name: " << name << std::endl;
}
void log_add(const std::string& name, std::multiset<std::string>& names)
{
auto now = std::chrono::system_clock::now();
std::string temp("abc");
logg(now, std::string("xxx"));
logg(now, "xxx");
logg(now, temp);
names.emplace(name);
}
template <typename T>
void log_add_T(T&& name, std::multiset<std::string>& names)
{
auto now = std::chrono::system_clock::now();
logg(now, "xxx");
names.emplace(std::forward<T>(name));
}
int main(int argc, char *argv[])
{
std::multiset<std::string> nameset;
log_add("abcd", nameset);
log_add_T("aaa", nameset);
return 0;
}

  


1. 如果采用logg函数的形式为 void logg(const time_point& tp, std::string& name), 则
    logg(now, std::string("xxx"));
    logg(now, "xxx");
  都会编译失败。

2. log_add_T函数采用万能引用参数,利用完美转发,效率比log_add高!

Modern Cpp记录的更多相关文章

  1. C++雾中风景番外篇4:GCC升级二三事

    最近将手头上负责的项目代码从GCC 4.8.2升级到了GCC 8.2.(终于可以使用C++17了,想想后续的开发也是很美好啊~~)不过这个过程之中也遇到了一些稀奇古怪的问题,在这里做一个简单的记录,希 ...

  2. C/C++头文件使用 #ifndef #define #endif 的原因

    背景 在编译的时候,出现"redefine"的错误,最后检查才发现对应的头文件没有写正确的预编译信息: #ifndef _HeadFileName_H #define _HeadF ...

  3. 跨平台渲染框架尝试 - constant buffer的管理

    1. Preface Constant buffer是我们在编写shader的时候,打交道最多的一种buffer resource了.constant表明了constant buffer中的数据,在一 ...

  4. c++11 move构造函数和move operator 函数 学习

    先看个代码吧!!!!!!!!!! #include <iostream> using namespace std; class A { public: A(){cout<<&q ...

  5. nlohmann 最优秀的C++序列化工具库 详细入门教程

    本文首发于个人博客https://kezunlin.me/post/f3c3eb8/,欢迎阅读最新内容! tutorial to use nlohmann json for serializing d ...

  6. 2019阿里JVM组实习面经

    面试质量非常高....非常高...高... 一面 自我介绍 看过hotspot哪些模块,模板解释器工作说一下,生成的native code放在哪,怎么处理safepoint的 说项目,实现了哪些字节码 ...

  7. 转:C++ 智能指针的正确使用方式

    转:https://www.cyhone.com/articles/right-way-to-use-cpp-smart-pointer/#comments C++11 中推出了三种智能指针,uniq ...

  8. ClickHouse源码笔记1:聚合函数的实现

    由于工作的需求,后续笔者工作需要和开源的OLAP数据库ClickHouse打交道.ClickHouse是Yandex在2016年6月15日开源了一个分析型数据库,以强悍的单机处理能力被称道. 笔者在实 ...

  9. 左值 lvalue,右值 rvalue 和 移动语义 std::move

    参考文章: [1] 基础篇:lvalue,rvalue和move [2] 深入浅出 C++ 右值引用 [3] Modern CPP Tutorial [4] 右值引用与转移语义 刷 Leetcode ...

随机推荐

  1. 多线程中fork与mutex

    在多线程程序中fork出一个新进程,发现新的进程无法正常工作.因为:在使用fork时会将原来进程中的所有内存数据复制一份保存在子进程中.但是在拷贝的时候,但是线程是无法被拷贝的.如果在原来线程中加了锁 ...

  2. python27期day14:有参装饰器、多个装饰器装饰一个函数、递归、作业题

    1.有参装饰器:给装饰器添加一个参数.来控制装饰器的行为. @auth(参数) auth里层的函数名 = auth(参数) 被装饰的函数名 = auth里层的函数名(被装饰的函数名) 被装饰的函数名( ...

  3. NOIP 2003 神经网络

    洛谷 P1038 神经网络 https://www.luogu.org/problemnew/show/P1038 JDOJ 1278: [NOIP2003]神经网络 T1 https://neooj ...

  4. Mysql 时间和日期函数

    参考文章 1 时间函数 当前日期和时间 select now(); 2 得到昨天的日期 CURDATE() 当前日期 select CURDATE()-1; -- curdate 3 添加时间间隔 当 ...

  5. workerman docker 运行试用

    看到别人项目使用了workerman 作为webserver ,看了下介绍发现此框架还是挺强大的,比较喜欢使用 docker运行软件,所以基于php 7.3 的基础镜像简单使用下 环境准备 项目使用了 ...

  6. bash shell——sum

    #!/bin/bash # sum.sh # 获取随机数量的参数,相加并打印结果 # total= # # $# 表示参数的数量 # for 循环获取每个参数 # ${!i} 表示返回第i个参数 # ...

  7. 2019CCPC网络预选赛 八道签到题题解

    目录 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 6702 & 6703 array 6704 K-th occurrence 6705 path 6706 huntian o ...

  8. PATA1075 PAT Judge (25 分)

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  9. [LeetCode] 915. Partition Array into Disjoint Intervals 分割数组为不相交的区间

    Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...

  10. [LeetCode] 43. Multiply Strings 字符串相乘

    Given two non-negative integers num1 and num2represented as strings, return the product of num1 and  ...