0

Update: The answer(s) and discussion provided in the existing answer are more than sufficient to satisfy this question.

If you have a similar question the suggested reading is this paper on user-defined literals and the std::literals::string_literals::operator""s reference


Reading through cppreference I came across this example. There is this trailing 's' at the end of the bad example and I am not sure what it signifies.

cppreference

eric
  • 1,029
  • 1
  • 8
  • 9
  • 1
    User-defined literals. Documentation on the specific example is here: http://en.cppreference.com/w/cpp/string/basic_string/operator%22%22s – Stephen Newell Apr 20 '18 at 03:25
  • 4
    The trailing `s` indicates that this should construct a `std::string`, which in this case is a temporary. Since `string_view` is non-owning, it doesn't increase the temporary's lifespan – Chad Apr 20 '18 at 03:25
  • But all the overloads of ""s operator takes length also as parameter so how is this working : "a temporary string"s – PapaDiHatti Apr 20 '18 at 03:36
  • @Kapil: `operator""s` is implicitly invoked by the literal expression. The compiler supplies the arguments. It knows them. – Cheers and hth. - Alf Apr 20 '18 at 04:05
  • The link provided above by @StephenNewell was what I was initially looking for. The paper here http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2378.pdf is also a thorough explanation. Thanks! – eric Apr 20 '18 at 04:17

0 Answers0