Skip to content

Instantly share code, notes, and snippets.

@kizzx2
Created April 20, 2011 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kizzx2/931832 to your computer and use it in GitHub Desktop.
Save kizzx2/931832 to your computer and use it in GitHub Desktop.
Compile time (static) length of string literal
#include <iostream>
template <size_t N>
inline void foo(const char (&)[N])
{
std::cout << "strlen(x) = " << N << std::endl;
}
int main()
{
foo("hello world");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment