lundi 2 décembre 2019

Two double quotes around preprocessor token in macro definition

I don't understand the significance of using two double quotes with strings in C++. I saw the following code somewhere:

class str_literal;
static str_literal operator"" _s(const char* s, size_t len);

class str_literal
{

  private:
  explicit str_literal(const char* s) : m_str(s) //&(STRING_LITERAL(s)))
  {
  } 
  const char* m_str;

  public:
  friend str_literal operator"" _s(const char* s, size_t len);
};

static str_literal operator"" _s(const char* s, size_t len)
{
  return str_literal(s);
}

#define S(str) "" str ""_s

Aucun commentaire:

Enregistrer un commentaire