C++ user defined literals

#include <chrono>
#include <thread>
#include <iostream>
using namespace std::chrono_literals;  //标准库的预定义文字量:用法:1000ms

using Ms = std::chrono::milliseconds;  //类型别名
auto operator "" _ms(unsigned long long value) { return Ms(value); }   //自定义的文字量,用法: 1000_ms

int main() {
    std::this_thread::sleep_for( std::chrono::millisecond(1000) );
    std::this_thread::sleep_for( Ms(3000) );
    std::this_thread::sleep_for( 3000_ms );
    std::this_thread::sleep_for( 3000ms );
}

3000ms !!我去。

posted @ 2018-03-20 13:01  thomas76  阅读(445)  评论(0编辑  收藏  举报