Search code examples
c++c++20

Which characters are valid in a user defined literal?


If I define a UDL like:

template <char... C> auto operator""_myUDL(){return 5;}

then what is the full range of legal arguments to _myUDL?


Solution

  • This form

    template <char... C> auto operator""_myUDL()
    

    can only be used for user-defined-integer-literals and user-defined-floating-point-literals.

    For integer literals, the possible characters are:

    • 0..9
    • A..F and a..f
    • X and x
    • '

    For floating-point literals, the possible characters are:

    • 0..9
    • A..F and a..f
    • X and x
    • '
    • .
    • P and p
    • + and -

    There might be more in the future.