Topic: Some questions about user defined literals


Author: restor <akrzemi1@interia.pl>
Date: Tue, 9 Jun 2009 15:48:33 CST
Raw View
> When I looked/searched through n2750 - i didn't see them mention any
> good reason for having yet another asymmetry added to the language.
> Could you point out the language in that paper that specifically
> addresses this issue?

3.3 "The raw-form operator". Look for "This restriction is added to
avoid specification and implementation difficulties."
This is the reason. I am not claiming it is "good" as I do not
understand it. However I believe it, as the details of string literals
are very beyond my comprehension. Baring in mind that string literals
can be concatenated, is this a valid string literal now?

L"text"L"text";

Is this one going to be valid?

u"u"t"u"t;

> Also do you agree that string literals can only be processed by a
> cooked literal operator and NOT a raw literal operator (as opposed to
> what Dr. Stroustrup's page suggests).  My sense is that this is
> probably a defect in the standard if he expects it to work.

My reading of the standart is the same as yours: only cooked string
literals (and no templates).

Regards,
&rzej


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Faisal Vali <faisalv@gmail.com>
Date: Sat, 23 May 2009 11:58:35 CST
Raw View
Stroustrup has a nice summary of most of the new C++0x features
(http://www.research.att.com/~bs/C++0xFAQ.htm - i find the summary to
be at a level that lets one appreciate the flavor of each feature
without getting mired by the details)

In the section on user defined literals, he writes:

<quote>
Literal operators that takes strings distinguish between cooked and
uncooked by a length argument:

       string operator "s"(const char* p, size_t n);   // calculate length
       string operator "S"(const char* p);             // preserve escapes, etc.

       "one\ttwo\n"s;  // cooked: operator "s"({'o', 'n', 'e', '\t', 't',
'w', 'o', '\n', 0} , 8);
       "one\ttwo\n"S;  // uncooked: operator "S"({'o', 'n', 'e', '\', 't',
't', 'w', 'o', '\', 'n', 0});
</quote>

Upon reading section 2.14.8 (n2857), it is not clear to me how the raw
literal operator (uncooked) would ever get called on a string
literal.  Specifically, paragraph 5 of that section mentions only one
possibility for user defined string literals.
Am I missing something?

Also, why is it that the literal operator templates can only be used
with integer or floating literals and not string literals?



thanks,
Faisal Vali
Radiation Oncology
Loyola



--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: restor <akrzemi1@interia.pl>
Date: Sun, 24 May 2009 15:13:27 CST
Raw View
> Also, why is it that the literal operator templates can only be used
> with integer or floating literals and not string literals?

Hi,
The rationale for that decision was described in the proposal N2750.
Basically it says that, because string literals are tricky, the cost
of implementing them would outweigh the benefit of having string
literal templates.

Regards,
&rzej

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Faisal Vali <faisalv@gmail.com>
Date: Fri, 29 May 2009 10:47:36 CST
Raw View
On May 24, 4:13 pm, restor <akrze...@interia.pl> wrote:
> > Also, why is it that the literal operator templates can only be used
> > with integer or floating literals and not string literals?
>
> Hi,
> The rationale for that decision was described in the proposal N2750.
> Basically it says that, because string literals are tricky, the cost
> of implementing them would outweigh the benefit of having string
> literal templates.

When I looked/searched through n2750 - i didn't see them mention any
good reason for having yet another asymmetry added to the language.
Could you point out the language in that paper that specifically
addresses this issue?

Also do you agree that string literals can only be processed by a
cooked literal operator and NOT a raw literal operator (as opposed to
what Dr. Stroustrup's page suggests).  My sense is that this is
probably a defect in the standard if he expects it to work.

regards,
Faisal Vali
Radiation Oncology
Loyola





thanks,
Faisal Vali





--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]