-
Notifications
You must be signed in to change notification settings - Fork 0
/
fn._i64 literal.html
342 lines (313 loc) · 13 KB
/
fn._i64 literal.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"></meta>
<meta name="generator" content="subdoc"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<meta property="og:type" content="website"></meta>
<meta property="og:site_name" content="Subspace"></meta>
<title>_i64 literal - Subspace</title>
<meta property="og:title" content="_i64 literal - Subspace"></meta>
<meta name="description" content="For writing i64 literals."></meta>
<meta property="og:description" content="For writing i64 literals."></meta>
<script src="https://unpkg.com/lunr/lunr.js"></script>
<script src="./search_db.js"></script>
<script>
// Delayed loading of whatever was in the search box.
var searchDelayLoad;
// The search box's dynamic behaviour.
document.addEventListener("keyup", e => {
if (e.key === 's') {
document.querySelector('.search-input').focus();
}
if (e.key === 'Escape') {
document.querySelector('.search-input').blur();
navigateToSearch(null);
e.preventDefault();
}
});
function navigateToSearch(query) {
window.clearTimeout(searchDelayLoad);
searchDelayLoad = null;
let without_search =
window.location.origin + window.location.pathname;
if (query) {
window.history.replaceState(null, "",
without_search + "?" + `search=${query}`);
} else {
window.history.replaceState(null, "", without_search);
}
maybeShowSearchResults();
}
addEventListener("load", event => {
document.querySelector(".search-input").oninput = (e) => {
window.clearTimeout(searchDelayLoad);
searchDelayLoad = window.setTimeout(() => {
navigateToSearch(e.target.value);
}, 1000);
};
document.querySelector(".search-input").onkeypress = (e) => {
if (e.key == "Enter") {
navigateToSearch(e.target.value);
e.preventDefault();
}
};
var searchPlaceholder;
document.querySelector(".search-input").onfocus = (e) => {
searchPlaceholder = e.target.placeholder;
e.target.placeholder = "Type your search here.";
navigateToSearch(e.target.value);
};
document.querySelector(".search-input").onblur = (e) => {
e.target.placeholder = searchPlaceholder;
searchPlaceholder = null;
};
});
// Show or hide any DOM element.
function showHide(selector, show) {
if (show)
document.querySelector(selector).classList.remove("hidden");
else
document.querySelector(selector).classList.add("hidden");
}
function searchQuery() {
const params = new Proxy(
new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
}
);
return params.search;
}
// Showing search results.
async function populateSearchResults(loaded) {
const search_db = loaded.search_db;
const idx = loaded.idx;
// lunrjs treats `:` specially and `::` breaks the query syntax, so
// just split into two words.
const query = searchQuery().split("::").join(" ");
let content = '';
try {
const results = idx.search(query);
for (r of results) {
const item = search_db[r.ref];
const type = item.type;
const url = item.url;
const name = item.name;
const full_name = item.full_name;
const summmary = item.summary ? item.summary : "";
content += `\
<a class="search-results-link" href="${url}">
<span class="search-results-type"><div>${type}</div></span>\
<span class="search-results-name"><div>${full_name}</div></span>\
<span class="search-results-summary"><div>${summmary}</div></span>\
</a>\
`
}
} catch (err) {
content +=
`<div class="search-error">Search error: ${err.message}</div>`;
}
let content_elem = document.querySelector(".search-results-content");
content_elem.innerHTML = content;
let header_elem = document.querySelector(".search-results-header");
header_elem.innerText = "Search results";
}
var cache_idx;
// Searching via https://lunrjs.com.
//
// Load the JSON search database, which will be turned into a search
// index. Returns an object with two fields:
// - search_db: the contents of the search.json file.
// - idx: the lunr search index.
// Documented at https://lunrjs.com/docs/lunr.Index.html.
async function loadSearchIndex() {
// This is not widely supported yet (not on Safari), so instead we
// turned the json file into a js file that sets a global variable. :|
//async function load_search_db() {
// let x = await import('./search.json', {
// with: {type: 'json'}
// });
// return x.default;
//}
async function load_idx(search_db) {
let idx = lunr(function () {
this.ref('index');
this.field('name', {
'boost': 2,
editDistance: 0
});
this.field('full_name', {
'boost': 2,
editDistance: 2
});
this.field('split_name', {
'boost': 0.5,
editDistance: 2
});
// No stemming and no stopwords (like `into` and `from`).
this.pipeline = new lunr.Pipeline();
this.searchPipeline = new lunr.Pipeline();
// Queries are split by these tokens.
const splitBy = /(\s+|_+|(::)+)/
this.use(builder => {
function splitTokens(token) {
return token.toString().split(splitBy).map(str => {
return token.clone().update(() => { return str })
})
}
lunr.Pipeline.registerFunction(splitTokens, 'splitTokens')
builder.searchPipeline.add(splitTokens)
});
search_db.forEach(item => {
const weights = {
"concept": 3,
"class": 2,
"struct": 2,
"union": 2,
"function": 1.75,
"variable": 1.75,
"namespace": 1.2,
"method": 1,
"constructor": 1,
"macro": 1,
"project": 1,
"field": 0.9,
"conversion": 0.5,
"type alias": 0.5,
"concept alias": 0.5,
"function alias": 0.5,
"method alias": 0.5,
"enum value alias": 0.5,
"variable alias": 0.5,
}
let weight = weights[item.type];
if (!weight) {
console.log(`WARNING: search item type ${item.type} ` +
`has no weight defined`);
weight = 1;
}
this.add(item, {
'boost': weight
})
}, this);
});
let out = {};
out.search_db = search_db;
out.idx = idx;
return out;
};
if (!cache_idx) {
cache_idx = await load_idx(g_search_db);
}
return cache_idx;
}
// If there's a search query, hide the other content and asynchronously
// show the search results. Otherwise, hide search content and show the
// rest immediately.
function maybeShowSearchResults() {
const query = searchQuery();
if (query) {
showHide(".main-content", false);
let input = document.querySelector(".search-input");
input.value = query;
let header_elem = document.querySelector(".search-results-header");
header_elem.innerText = "Loading search results...";
let content_ele = document.querySelector(".search-results-content");
content_ele.innerText = "";
loadSearchIndex().then(populateSearchResults)
} else {
showHide(".main-content", true);
let header_elem = document.querySelector(".search-results-header");
header_elem.innerText = "";
let content_ele = document.querySelector(".search-results-content");
content_ele.innerText = "";
}
}
</script>
<link rel="stylesheet" href="subdoc-test-style.css">
<link rel="icon" type="image/png" href="logo.png">
<link rel="alternate icon" type="image/png" href="logo32.png">
<link rel="alternate icon" type="image/png" href="logo16.png">
<meta property="og:image" content="logo.png"></meta>
</head>
<body>
<nav class="topbar">
<button class="sidebar-menu-button" onclick="let e = document.getElementsByClassName('sidebar')[0];e.classList.toggle('shown');">
☰
</button>
<a class="topbar-logo-link" href="index.html"><div class="topbar-logo-border">
<img class="topbar-logo" src="logo.png"></img>
</div></a>
<span class="topbar-text-area">
<span class="topbar-title">
<a href="#">_i64 literal</a>
</span>
</span>
</nav>
<nav class="sidebar">
<a class="sidebar-logo-link" href="index.html"><div class="sidebar-logo-border">
<img class="sidebar-logo" src="logo.png"></img>
</div></a>
<div class="sidebar-pretitle sidebar-text">
function
</div>
<div class="sidebar-title sidebar-text">
<a href="#">_i64 literal</a>
</div>
<div class="sidebar-subtitle sidebar-text">
</div>
<div class="sidebar-links sidebar-text">
<ul>
</ul>
</div>
</nav>
<main>
<nav class="search-nav">
<form class="search-form">
<input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press 'S' to search...">
</input>
</form>
</nav>
<section class="search-results">
<h1 class="search-results-header">
</h1>
<div class="search-results-content">
</div>
</section>
<section class="main-content">
<script>maybeShowSearchResults()</script>
<div class="function">
<div class="section overview">
<h1 class="section-header">
<span>
Function
</span>
<a class="project-name" href="index.html">Subspace</a>
<span class="namespace-dots">::</span>
<a class="function-name" href="#">_i64 literal</a>
</h1>
<div class="overload-set">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/num/signed_integer.h#L479">source</a></div><span class="function-auto">auto</span> <a class="function-name" href="#">operator""_i64</a>(unsigned long long val) -> <a class="type-name" href="sus-num-i64.html" title="sus::num::i64">i64</a></div>
</div>
</div>
<div class="description long">
<p>For writing <a href="sus-num-i64.html"><code>i64</code></a> literals.</p>
<p>Un-qualified integer literals are 32 bits large (the size of <code>int</code>), unless
a literal suffix modifies them, such as with <code>_i64</code> which creates a 64-bit
value. On Windows, this is the same as the <code>l</code> suffix (which makes a
<code>long</code>) but is platform agnostic, and forces a safe numeric type instead of
a primitive value when this is needed (such as for templates or member
function access).</p>
<p>Values out of range for <a href="sus-num-i64.html"><code>i64</code></a> will fail to compile.</p>
<h1><a name="examples" href="#examples">Examples</a></h1>
<pre><code><span class="keyword">auto</span> i <span class="punct">=</span> 123_i64 <span class="punct">-</span> <span class="punct">(</span>5_i64<span class="punct">)</span><span class="punct">.</span>abs<span class="punct">(</span><span class="punct">)</span><span class="punct">;</span>
sus_check<span class="punct">(</span>i <span class="punct">=</span><span class="punct">=</span> 118_i64<span class="punct">)</span><span class="punct">;</span>
</code></pre>
</div>
</div>
</div>
</section>
</main>
</body>
</html>