Daniel Lemire's blog

, 5 min read

Having fun with string literal suffixes in C++

7 thoughts on “Having fun with string literal suffixes in C++”

  1. TatLim says:

    The very first sentence contains a typo ‘used-defined’ which should be changed to ‘user-defined’. The second paragraph contains another typo ‘so you can write R”(\d+)” ‘ which should be changed to ‘so you can write R”(\d+)” ‘

    1. Thanks.

  2. Pavel says:

    Thanks Daniel! Do you know of any practical applications for operator””? Operator overloading has become frowned upon for its obscurity, but this one has the potential to carry meaningful names.

    1. Operator overloading has become frowned upon

      I think that’s different from standard operator overloading. You have to specify a suffix, so you can’t use it by accident.

      Do you know of any practical applications for operator””?

      We use it in the simdjson library.

  3. Marcus says:

    Off topic, but what’s your opinion of adding operator overloading to C, in a way that the user would name the function that implements that operator, and therefore doesn’t require name mangling?

    It’s an idea I’ve been kicking around.

    1. Operator overloading in C or in C++?

      1. Marcus says:

        In regular, old fashioned C.

        I’m thinking something like: _Operator = UTF8String_Init;

        Where UTF8String_Init is a previously declared function.

        Implementation details could still be hidden, the _Operator declaration could be in a header too, and no name mangling necessary since the function has already been named by the programmer.

        No need for a class to contain it either, since the types could be desuced from the parameters of the named function e.g: UTF8String UTF8String_Init(char8_t *Characters);

        And for strings, I don’t see why there couldn’t be multiple variants for the same operator.

        Like:

        UTF8String UTF8String_InitFromChars(char8_t *Chars);

        UTF8String UTF8String_InitFromChar(char8_t Char);

        _Overload = UTF8String_InitFromChar;

        _Overload = UTF8String_InitFromChars;

        Basically, soft function overloading, but with better names.