If my code has this constexpr
string
constexpr char my_str[] = "hello";
the type of my_str
contains information about its size, i.e. sizeof(my_str)
is a constant 6, and can be used anywhere a constant is required.
What about strlen(my_str)
? Can/should it also be evaluated to a compile-time constant?
Here is an example for yes: https://ideone.com/2U65bN
Here is an example for no: http://coliru.stacked-crooked.com/a/8cb094776dfc5969
What does the Standard say about this? Surely not "maybe"?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…