Bjarne Stroustrup gave a keynote presentation today for the Going Native 2012 conference. In his presentation, he discussed the issue of enforcing correct units. His elegant (IMHO) solution to this involved using an operator I have never heard of before: operator""
. Using this operator, he was able to write C++ code that looked like this:
ratio = 100m / 1s;
Where operator""m(...)
and operator""s(...)
were defined.
Does anyone know of any documentation regarding how to actually use this operator (or even if any modern C++ compilers support it)? I tried searching online, but had no luck. Any help would be greatly appreciated.
Arithmetic Operators are used to perform mathematical calculations. Assignment Operators are used to assign a value to a property or variable. Assignment Operators can be numeric, date, system, time, or text. Comparison Operators are used to perform comparisons.
The three most commonly used operators are AND, OR, NOT. These are known as Boolean operators. They can be used to broaden or narrow a search and to exclude unwanted search terms and concepts. You can type these operators in between your search terms (Fig.
Two or more relations can be logically joined using the logical operators AND and OR . Logical operators combine relations according to the following rules: The ampersand (&) symbol is a valid substitute for the logical operator AND . The vertical bar ( | ) is a valid substitute for the logical operator OR .
The syntax you'd be looking for is "user-defined literals" which is a feature of C++11.
g++ versions 4.7 and better support this feature.
Here is some documentation describing the use of that operator overload: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf
Also see the excellent link Xeo provides in the comments to your question.
Currently the best documentation is probably in the standard itself. You can get the latest version from the commitee's site. According to gcc's site it will be in the next revision of gcc (gcc-4.7). You should be able to test it when building gcc from the SVN repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With