Are there user-defined-literals for variables?

901 views Asked by At

The user-defined-literals from C++11 helps the integers and float numbers have certain units like m, cm, mm, km, and so on. But it seems that it deals only with constant. I have a runtime program which always calculates some lengths and convert them between different units. Are there also similar mechanisms like user-defined-literals in C++ for variables?

1

There are 1 answers

0
Jens On

To my knowledge, the C++14 standard provides literal operators for complex numbers, string, string_view and std::chrono time values.. There are no operators defined for other SI units, and there no classes supporting this in the standard.

There are libraries to define unit systems, e.g. Boost.Units. However, as far I read the docs, Boost.Units does not defined user-defined literal operator. But then it should be easy to do it on your own.