The main motivation behind wanting a string literal with external linkage is to use string literals as non-type template parameters.
I would imagine a string literal with external linkage having a definition similar to
A string-literal that has an e in the prefix is a string-literal with external linkage.
template<auto&> struct S{}; void bar() { S<e"foo"> s; }
will have behaviour equivalent to
template<auto&> struct S{}; constexpr char __foo[] = "foo"; void bar { S<__foo> s; }
Is there a reason not to have external linkage string literals?
Does somehow adding another prefix (like e"Lorem Ipsum"
) to make a string literal have external linkage detrimental?
Note: it is already possible to achieve an external linkage string, but it is a god awful way to do things.
#include<boost/metaparse/v1/string.hpp>
template<typename>
struct hack;
template<char... Cs>
struct hack<boost::metaparse::v1::string<Cs...>>
{
static constexpr char arr[] = {Cs..., '\0'};
};
#define E(str) hack<BOOST_METAPARSE_STRING(str)>::arr
template<auto&> struct S{};
S<E("I'm an external linkage string")> s; // compiles
Boost uses a python script to generate the implementation of BOOST_METAPARSE_STRING
, and that is terrible.