Back to TILs

How can I obtain the length of a string at compile time?

Table of contents

Objective

To obtain, at compile time, the length of a compile-time string constant.

Solution

constexpr len1 = std::string::traits_type::length("Geraldo");
// or
constexpr len2 = std::char_traits<char>::length("Ribeiro");

Reference