- Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathstring.cxx
39 lines (30 loc) · 984 Bytes
/
string.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<cstdio>
#include<string>
#include<algorithm>
template<constchar name[]>
voidfunc() {
@meta printf("func<%s> instantiated\n", name);
}
intmain() {
// Instantiate on a string literal.
func<"My string literal">();
// Instantiate on a constexpr or meta const char array.
constexprchar array[] = "My constexpr string";
func<array>();
@meta char array2[] = "My meta string";
func<array2>();
// Instantiate on a constexpr or meta pointer to character.
constexprconstchar* ptr = "My constexpr string";
func<ptr>();
@meta constchar* ptr2 = "My meta string";
func<ptr2>();
// Instantiate on a meta std::string. This is not a literal type so must
// be made meta.
@meta std::string s = "My meta string";
func<s>();
// The strings can be modified at compile time. They can come from any
// source. They don't have to refer to literals!
@meta std::transform(s.begin(), s.end(), s.begin(), toupper);
func<s>();
return0;
}