operator""if imaginary float std::literals::complex_literals
operator""I imaginary double std::literals::complex_literals
operator""il imaginary long std::literals::complex_literals
operator""h hours std::literals::chrono_literals
operator""min minutes std::chrono::duration
operator""s seconds std::chrono::duration
operator""ms milliseconds std::chrono::duration
operator""us microseconds std::chrono::duration
operator""ns nanoseconds std::chrono::duration
operator""s string std::literals::string_literals
Here is an example:
#include <chrono>
#include <complex>
#include <iostream>
int main()
{
using namespace std::complex_literals;
std::cout << 1.1if << " ";
std::cout << 2.2i << " ";
std::cout << 3il << " ";
using namespace std::chrono_literals;
std::cout << std::chrono::seconds (4h ).count() << " ";
std::cout << std::chrono::seconds (5min).count() << " ";
std::cout << std::chrono::seconds (6s ).count() << " ";
std::cout << std::chrono::nanoseconds(7ms ).count() << " ";
std::cout << std::chrono::nanoseconds(8us ).count() << " ";
std::cout << std::chrono::nanoseconds(9ns ).count() << " ";
using namespace std::string_literals;
std::cout << "Hello"s << " ";
std::cout << std::endl;
return 0;
}
// Output: (0,1.1) (0,2.2) (0,3) 14400 300 6 7000000 8000 9 Hello
Reference: http://en.cppreference.com/w/cpp/language/user_literal
No comments:
Post a Comment