I want to write some function that takes a string literal - and only a string literal:
template
void foo(const char (&s
Depending on what exactly you want, this may or may not work for you:
#include
template
void foo(const char (&str)[N]) {}
template struct check_literal {};
#define foo(arg) foo((check_literal(),arg))
int main()
{
// This compiles
foo("abc");
// This does not
static const char abc[] = "abc";
foo(abc);
}
This works with g++ and clang++ in -std=c++11
mode only.