Raw and Cooked

Let's look at the two different types of literal operators.

We'll cover the following

The literal operator is available in two types:

  1. Raw
  2. Cooked

Raw #

The raw form accepts its arguments as (const char*, size_t), (const char*) or const char:

1.45_km => operator "" _km("1.45")

The raw string literals we talked about earlier fall under this category.

Cooked #

Accepts its arguments as long double or unsigned long long int:

1.45_km => operator "" _km(1.45)

One thing to keep in mind is that there has to be a space between "" and _km. Also, user-defined literals should start with an underscore (_km) to distinguish them from the built-in literals.

The cooked and raw forms are available for natural numbers and floating point numbers. However, only raw literal operators work with C-string literals and character literals.

Before we get into detail, here are the literal types including the raw and cooked variations:

Get hands-on with 1400+ tech skills courses.