Skip to content

Instantly share code, notes, and snippets.

@Newlifer
Created July 20, 2016 10:53
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 Newlifer/c2fc860c6c1de929c16c42d1e6abbb8d to your computer and use it in GitHub Desktop.
Save Newlifer/c2fc860c6c1de929c16c42d1e6abbb8d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
template <char... Characters>
struct string_literal {
static const std::size_t string_length = sizeof...(Characters);
static constexpr char str[string_length] = {Characters...};
};
template <char... Characters>
constexpr char string_literal<Characters...>::str[];
template <typename CharT, CharT ...String>
constexpr auto operator "" _op() -> string_literal<String...>
{
return string_literal<String...>();;
}
template <typename T>
struct foo
{
typedef T literal;
};
typedef foo<decltype("hello!"_op)> foo_fak;
int main() {
std::cout << foo_fak::literal::str << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment