Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #41091

Re: "²" - stray '\262' in program

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: "²" - stray '\262' in program
Date 2016-02-21 22:15 +0100
Organization A noiseless patient Spider
Message-ID <nad97a$mvj$1@dont-email.me> (permalink)
References <exponentiation-20160221003041@ram.dialup.fu-berlin.de> <nab07i$8ti$1@dont-email.me> <HOudnRN5GZdmvlfLnZ2dnUU78R2dnZ2d@brightview.co.uk>

Show all headers | View raw


On 21.02.2016 21:54, Vir Campestris wrote:
> On 21/02/2016 00:29, Alf P. Steinbach wrote:
>> Or you can do this:
>>
>>      #include <iostream>
>>
>>      constexpr auto operator""_²( long double const d )
>>          -> long double
>>      { return d*d; }
>>
>>      auto main() -> int { std::cout << 3.00_² << '\n'; }
>>
>> Except for the non-conforming behavior of g++, of course. <g/>
>
> Alf, I'm obviously not up to date on the standards here. Last time I
> rummaged you could only define operator <something> where <something>
> was one of the standard operators, like +. Could you give me a link
> where I can read about this stuff please?

Oh, they're C++11 user defined literals. That is, a way to define a 
suffix for a literal, so that the compiler invokes a corresponding 
function to produce whatever you want for that suffix. E.g. the standard 
provides suffix `s` to generate a `std::string`, like the literal 
`"blah"s` (the compiler passes "blah" to a conversion func).

General discussion in the FAQ:
<url: https://isocpp.org/wiki/faq/cpp11-language#udls>

Technical info, nearly as good as the standard:
<url: http://en.cppreference.com/w/cpp/language/user_literal>.


> I seriously thought my newsreader was trying to do something clever,
> like when it turns : ) (without a space) into a smiley.

:)


Cheers & hth.,

- Alf

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: "²" - stray '\262' in program "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-21 01:29 +0100
  Re: "²" - stray '\262' in program David Brown <david.brown@hesbynett.no> - 2016-02-21 12:30 +0100
  Re: "²" - stray '\262' in program Vir Campestris <vir.campestris@invalid.invalid> - 2016-02-21 20:54 +0000
    Re: "²" - stray '\262' in program "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-21 22:15 +0100
      Re: "²" - stray '\262' in program Vir Campestris <vir.campestris@invalid.invalid> - 2016-02-23 21:42 +0000

csiph-web