Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone have information on using operator""?

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.

like image 592
Joseph Buntic Avatar asked Feb 02 '12 20:02

Joseph Buntic


People also ask

What is the use of operator?

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.

What are the 3 operators that can be used in search terms?

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.

Where do we use and operators?

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 .


2 Answers

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.

like image 106
Tom B Avatar answered Oct 20 '22 15:10

Tom B


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.

like image 42
Dietmar Kühl Avatar answered Oct 20 '22 15:10

Dietmar Kühl