-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsus-boxed-Box.html
1022 lines (966 loc) · 64.8 KB
/
sus-boxed-Box.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!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>
<meta property="og:url" content="https://suslib.cc/sus-boxed-Box.html"></meta>
<title>sus::boxed::Box - Subspace</title>
<meta property="og:title" content="sus::boxed::Box - Subspace"></meta>
<meta name="description" content="A heap allocated object."></meta>
<meta property="og:description" content="A heap allocated object."></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">
<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="#">Box</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">
class
</div>
<div class="sidebar-title sidebar-text">
<a href="#">Box</a>
</div>
<div class="sidebar-subtitle sidebar-text">
</div>
<div class="sidebar-links sidebar-text">
<ul>
<li>
<a class="sidebar-header" href="#static-methods">Static Methods</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.Box.ctor.convert">Box</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.Box.ctor.inherit">Box</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.Box.move">Box</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.Box">Box</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.from.convert">from</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.from.inherit">from</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.from.dync">from</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.from.dynerror">from</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.from_raw">from_raw</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.with_args">with_args</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.with_default">with_default</a>
</li>
<li>
<a class="sidebar-header" href="#methods">Methods</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.as_mut">as_mut</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.as_ref">as_ref</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.clone">clone</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.clone_from">clone_from</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.exact_size_hint">exact_size_hint</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.into_inner">into_inner</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.into_raw">into_raw</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.leak">leak</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.next">next</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.next_back">next_back</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.size_hint">size_hint</a>
</li>
<li>
<a class="sidebar-header" href="#operators">Operators</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.operator()">operator()</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.operator*">operator*</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.operator->">operator-></a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.operator=.move">operator=</a>
</li>
<li>
<a class="sidebar-item" href="sus-boxed-Box.html#method.operator=">operator=</a>
</li>
</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="type record class">
<div class="section overview">
<h1 class="section-header">
<span>
Class
</span>
<a class="project-name" href="index.html">Subspace</a>
<span class="namespace-dots">::</span>
<a class="namespace-name" href="namespace.sus.html">sus</a>
<span class="namespace-dots">::</span>
<a class="namespace-name" href="sus-namespace.boxed.html">boxed</a>
<span class="namespace-dots">::</span>
<a class="type-name" href="#">Box</a>
</h1>
<div class="type-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L132">source</a></div><pre class="template">template <class T></pre><span class="class">
class
</span><span class="type-name">
Box
</span><span class="final">
final
</span><div class="record-body">
{ ... };
</div></div>
<div class="description long">
<p>A heap allocated object.</p>
<p>A <code>Box<T></code> holds ownership of an object of type <code>T</code> on the heap. When <code>Box</code>
is destroyed, or an rvalue-qualified method is called, the inner heap
object is freed.</p>
<p><code>Box</code> is similar to <a href="https://en.cppreference.com/w/cpp/memory/unique_ptr"><code>std::unique_ptr</code></a> with some differences,
and should be preferred when those differences will benefit you:</p>
<ul>
<li>Const correctness. A <code>const Box</code> treats the inner object as <code>const</code> and
does not expose mutable access to it.</li>
<li>Never null. A <code>Box</code> always holds a value until it is moved-from. It is
constructed from a value, not a pointer. Alternatively it can be
constructed from the constructor arguments by
<a href="sus-boxed-Box.html#method.with_args"><code>with_args</code></a>, like <a href="https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique"><code>std::make_unique</code></a>
but built into the type.
A moved-from <code>Box</code> may not be used except to be assigned to or destroyed.
Using a moved-from <code>Box</code> will <a href="macro.sus_panic.html"><code>panic</code></a> and
terminate the program rather than operate on a null. This prevents
Undefined Behaviour and memory bugs caused by dereferencing null or using
null in unintended ways.</li>
<li>Supports up-casting (TODO: and <a href="https://github.com/chromium/subspace/issues/333"><code>down-casting</code></a>) without leaving
requiring a native pointer to be pulled out of the <code>Box</code>.</li>
<li>No native arrays, <code>Box</code> can hold <a href="sus-collections-Array.html"><code>Array</code></a> or
<a href="https://en.cppreference.com/w/cpp/container/array"><code>std::array</code></a> but
avoids API complexity for supporting pointers and native arrays (which
decay to pointers) by rejecting native arrays.</li>
<li>Integration with <a href="sus-boxed-DynConcept.html">concept type-erasure</a> for
holding and constructing from type-erased objects which satisfy a given
concept in a type-safe way and without requiring inheritence. This
construction is done through <a href="sus-construct-From.html"><code>From</code></a> and thus
can <code>Box<DynC></code> can be constructed in a type-deduced way from any object
that satisfies the concept <code>C</code> via <a href="sus-construct-fn.into.html"><code>sus::into()</code></a>.
This only requires that <code>DynC</code> is compatible with
<a href="sus-boxed-DynConcept.html"><code>DynConcept</code></a> which is the case for all
type-erasable concepts in the Subspace library.</li>
<li>Additional integration with Subspace library concepts like
<a href="sus-error-Error.html"><code>Error</code></a> and <a href="sus-fn-Fn.html"><code>Fn</code></a> such that <code>Box</code>
<a href="#box-implements-some-concepts-for-its-inner-type">will satisfy those concepts itself</a> when holding
a type-erased object that satisfies those concepts.</li>
</ul>
<h1><a name="box-implements-some-concepts-for-its-inner-type" href="#box-implements-some-concepts-for-its-inner-type">Box implements some concepts for its inner type</a></h1>
<p>The Subspace library provides a number of concepts which support
type-erasure through <a href="sus-boxed-DynConcept.html"><code>DynConcept</code></a>, and when
<code>Box</code> is holding these as its value, it may itself implement the concept,
forwarding use of the concept through to the inner type.</p>
<p>The canonical example of this is
<a href="sus-result-Result.html"><code>Result</code></a><code><T, Box<</code><a href="sus-error-DynError.html"><code>DynError</code></a><code>>></code>, which allows construction via
<code>sus::err(sus::into(e))</code> for any <code>e</code> that satisfies
<a href="sus-error-Error.html"><code>Error</code></a>. The error field, now being a <code>Box</code> is still
usable as an <a href="sus-error-Error.html"><code>Error</code></a> allowing generic code that
expects the <a href="sus-result-Result.html"><code>Result</code></a> to hold an
<a href="sus-error-Error.html"><code>Error</code></a> to function even though the actual error has
been type-erased and no longer needs the functions to be templated on it.</p>
<p>The following concepts, when type-erased in <code>Box</code> will also be satisfied
by the <code>Box</code> itself, avoiding the need to unwrap the inner type and allowing
the <code>Box</code> to be used in templated code requiring that concept:</p>
<ul>
<li><a href="sus-error-Error.html"><code>Error</code></a></li>
<li><a href="sus-fn-Fn.html"><code>Fn</code></a></li>
<li><a href="sus-fn-FnMut.html"><code>FnMut</code></a></li>
<li><a href="sus-fn-FnOnce.html"><code>FnOnce</code></a></li>
<li><a href="sus-iter-Iterator.html"><code>Iterator</code></a></li>
<li><a href="sus-iter-DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a></li>
<li><a href="sus-iter-ExactSizeIterator.html"><code>ExactSizeIterator</code></a></li>
</ul>
</div>
</div>
<div class="section methods static">
<h1 class="section-header">
<a name="static-methods" href="#static-methods">Static Methods</a>
</h1>
<div class="section-items">
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L142">source</a></div><a name="method.Box.ctor.convert"></a><div class="template">template <class U></div><a class="function-name" href="sus-boxed-Box.html#method.Box.ctor.convert">Box</a>(U u)<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">std::convertible_to<U, T></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">!::sus::ptr::SameOrSubclassOf<U*, T*></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Move<U></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Constructs a Box which allocates space on the heap and moves <code>T</code> into it.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L150">source</a></div><a name="method.Box.ctor.inherit"></a><div class="template">template <class U></div><a class="function-name" href="sus-boxed-Box.html#method.Box.ctor.inherit">Box</a>(U u)<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::ptr::SameOrSubclassOf<U *, T *></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Move<U></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Constructs a Box which allocates space on the heap and moves <code>T</code> into it.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L245">source</a></div><a name="method.Box.move"></a><a class="function-name" href="sus-boxed-Box.html#method.Box.move">Box</a>(<a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T>&& rhs)</div>
</div>
</div>
<div class="description long">
<p>Satisifes the <a href="sus-mem-Move.html"><code>Move</code></a> concept for
<a href="sus-boxed-Box.html"><code>Box</code></a>.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L251">source</a></div><a name="method.Box"></a><div class="template">template <class U></div><a class="function-name" href="sus-boxed-Box.html#method.Box">Box</a>(<a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><U>&& rhs)<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::ptr::SameOrSubclassOf<U *, T *></pre></div>
</div></div>
</div>
</div>
<div class="description long">
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L198">source</a></div><a name="method.from.convert"></a><div class="template">template <class U></div><span class="static">static</span> <span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.from.convert">from</a>(U u) -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">std::convertible_to<U, T></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">!::sus::ptr::SameOrSubclassOf<U*, T*></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Move<U></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Converts <code>U</code> into a <a href="sus-boxed-Box.html"><code>Box<T></code></a>.</p>
<p>The conversion allocates on the heap and moves <code>u</code> into it.</p>
<p>Satisfies the <a href="sus-construct-From.html"><code>From<U></code></a> concept for
<a href="sus-boxed-Box.html"><code>Box<T></code></a> where <code>U</code> is convertible to <code>T</code> and is not a
subclass of <code>T</code>.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L212">source</a></div><a name="method.from.inherit"></a><div class="template">template <class U></div><span class="static">static</span> <span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.from.inherit">from</a>(U u) -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::ptr::SameOrSubclassOf<U *, T *></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Move<U></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Converts <code>U</code> into a <a href="sus-boxed-Box.html"><code>Box<T></code></a>.</p>
<p>The conversion allocates on the heap and moves <code>u</code> into it.</p>
<p>Satisfies the <a href="sus-construct-From.html"><code>From<U></code></a> concept for
<a href="sus-boxed-Box.html"><code>Box<T></code></a> where U is <code>T</code> or a subclass of <code>T</code>.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L306">source</a></div><a name="method.from.dync"></a><div class="template">template <class U></div><span class="static">static</span> <span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.from.dync">from</a>(U u) -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Move<U></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">std::same_as<U, std::remove_cvref_t<U>></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::boxed::DynConcept<T, U></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">T::template SatisfiesConcept<U></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>For a type-erased <code>DynC</code> of a concept <code>C</code>, <code>Box<DynC></code> can be
constructed from a type that satisfies <code>C</code>.</p>
<p>This satisfies the <a href="sus-construct-From.html"><code>From<DynC, C></code></a> concept for
constructing <code>Box<DynC></code> from any type that satisfies the concept <code>C</code>. It
allows returning a non-templated type satisfying a concept.</p>
<p>See <a href="sus-boxed-DynConcept.html"><code>DynConcept</code></a> for more on type erasure of
concept-satisfying types.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L325">source</a></div><a name="method.from.dynerror"></a><span class="static">static</span> <span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.from.dynerror">from</a>(std::string s) -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">std::same_as<T, ::sus::error::DynError></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Satisfies the <a href="sus-construct-From.html"><code>From<std::string></code></a> concept for
<a href="sus-boxed-Box.html"><code>Box</code></a><code><</code><a href="sus-error-DynError.html"><code>DynError</code></a><code>></code>. This
conversion moves and type-erases the <code>std::string</code> into a heap-alloocated
<a href="sus-error-DynError.html"><code>DynError</code></a>.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L344">source</a></div><a name="method.from_raw"></a><span class="static">static</span> <span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.from_raw">from_raw</a>(<a class="type-name" href="sus-marker-UnsafeFnMarker.html" title="sus::marker::UnsafeFnMarker">UnsafeFnMarker</a>, T* raw) -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T></div>
</div>
</div>
<div class="description long">
<p>After calling this function, the raw pointer is owned by the resulting
Box. Specifically, the Box destructor will call the destructor of T and
free the allocated memory. For this to be safe, the memory must have been
allocated on the heap in the same way as the <code>Box</code> type, using
<a href="https://en.cppreference.com/w/cpp/memory/new/operator_new"><code>operator new</code></a> and must not be
an array.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L184">source</a></div><a name="method.with_args"></a><div class="template">template <class... Args></div><span class="static">static</span> <span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.with_args">with_args</a>(Args&&... args) -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">std::constructible_from<T, Args &&...></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Constructs a Box by calling the constructor of <code>T</code> with <code>args</code>.</p>
<p>This allows construction of <code>T</code> directly on the heap, which is required
for types which do not satisfy <a href="sus-mem-Move.html"><code>Move</code></a>. This is a common
case for virtual clases which require themselves to be heap allocated.</p>
<p>For type-erasure of concept objects using <a href="sus-boxed-DynConcept.html"><code>DynConcept</code></a>, such as <a href="sus-error-DynError.html"><code>DynError</code></a>,
the <a href="sus-boxed-Box.html#method.from.dync"><code>from</code></a> constructor method
can be used to type erase the concept object and move it to the heap.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L166">source</a></div><a name="method.with_default"></a><span class="static">static</span> <span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.with_default">with_default</a>() -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::construct::Default<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Constructs <code>Box<T></code> with the default value for the type <code>T</code>.</p>
<p><code>Box</code> can not satisfy <a href="sus-construct-Default.html"><code>Default</code></a> because it
prevents C++ from using <code>Box</code> to build recursive types where <code>T</code> holds
an <code>Option<Box<T>></code> as a member.</p>
</div>
</div>
</div>
<div class="section methods nonstatic">
<h1 class="section-header">
<a name="methods" href="#methods">Methods</a>
</h1>
<div class="section-items">
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L350">source</a></div><a name="method.as_mut"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.as_mut">as_mut</a>() & -> T&</div>
</div>
</div>
<div class="description long">
<p>Converts <code>Box</code> into a mutable reference of the inner type.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L356">source</a></div><a name="method.as_ref"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.as_ref">as_ref</a>() const& -> <span class="const">const</span> T&</div>
</div>
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L356">source</a></div><a name="method.as_ref"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.as_ref">as_ref</a>() && -> <span class="const">const</span> T&<div class="deleted">
deleted
</div></div>
</div>
</div>
<div class="description long">
<p>Converts <code>Box</code> into a const reference of the inner type.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L222">source</a></div><a name="method.clone"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.clone">clone</a>() const -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Clone<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Returns a new box with a clone() of this box’s contents.</p>
<p>Satisfies the <a href="sus-mem-Clone.html"><code>Clone</code></a> concept if <code>T</code> satisfies
<a href="sus-mem-Clone.html"><code>Clone</code></a>.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L234">source</a></div><a name="method.clone_from"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.clone_from">clone_from</a>(<span class="const">const</span> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T>& rhs) -> void<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Clone<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Copies <code>source</code>'s contents into the contained <code>T</code> without creating a new
allocation.</p>
<p>An optimization to reuse the existing storage for
<a href="sus-mem-fn.clone_into.html"><code>clone_into</code></a>.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L643">source</a></div><a name="method.exact_size_hint"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.exact_size_hint">exact_size_hint</a>() const -> sus::usize<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::iter::IteratorAny<T></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::iter::ExactSizeIterator<T, typename T::Item></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Implements <a href="sus-iter-ExactSizeIterator.html"><code>ExactSizeIterator</code></a> if
<code>T</code> is an <a href="sus-iter-ExactSizeIterator.html"><code>ExactSizeIterator</code></a>,
forwarding through to the inner <code>T</code> object.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L366">source</a></div><a name="method.into_inner"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.into_inner">into_inner</a>() && -> T<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::mem::Move<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Consumes the <code>Box</code>, returning the wrapped value.</p>
<p>This allows the caller to make use of the wrapped object as an rvalue
without leaving a moved-from <code>T</code> inside the <code>Box</code>.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L411">source</a></div><a name="method.into_raw"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.into_raw">into_raw</a>() && -> T*</div>
</div>
</div>
<div class="description long">
<p>Consumes the <code>Box</code>, returning a wrapped raw pointer.</p>
<p>The pointer will be properly aligned and non-null.</p>
<p>After calling this function, the caller is responsible for the memory
previously managed by the <code>Box</code>. In particular, the caller should properly
destroy <code>T</code> and
<a href="https://en.cppreference.com/w/cpp/memory/new/operator_delete">delete</a> the
memory, taking into account the alignment if any that would be passed by
<code>Box</code> to <a href="https://en.cppreference.com/w/cpp/memory/new/operator_new"><code>operator new</code></a>. The easiest
way to do this is to convert the raw pointer back back into a <code>Box</code> with
the <a href="sus-boxed-Box.html#method.from_raw"><code>Box::from_raw</code></a> function, allowing the
<code>Box</code> destructor to perform the cleanup.</p>
<p>Note: this is a not a static function, unlike the matching Rust function
<a href="https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#method.into_raw"><code>Box::into_raw</code></a>,
since in C++ the <code>Box</code> can not expose the methods of the inner type
directly.</p>
<h1><a name="examples" href="#examples">Examples</a></h1>
<p>Converting the raw pointer back into a <code>Box</code> with
<a href="sus-boxed-Box.html#method.from_raw"><code>Box::from_raw</code></a> for automatic cleanup:</p>
<pre><code><span class="keyword">auto</span> x <span class="punct">=</span> Box<span class="punct"><</span>std::string<span class="punct">></span><span class="punct">(</span><span class="string">"Hello"</span><span class="punct">)</span><span class="punct">;</span>
<span class="keyword">auto</span><span class="punct">*</span> ptr <span class="punct">=</span> sus::move<span class="punct">(</span>x<span class="punct">)</span><span class="punct">.</span>into_raw<span class="punct">(</span><span class="punct">)</span><span class="punct">;</span>
x <span class="punct">=</span> Box<span class="punct"><</span>std::string<span class="punct">></span>::from_raw<span class="punct">(</span>unsafe_fn<span class="punct">,</span> ptr<span class="punct">)</span><span class="punct">;</span>
</code></pre>
<p>Manual cleanup by explicitly running the destructor and deallocating the
memory:</p>
<pre><code><span class="keyword">auto</span> x <span class="punct">=</span> Box<span class="punct"><</span>std::string<span class="punct">></span><span class="punct">(</span><span class="string">"Hello"</span><span class="punct">)</span><span class="punct">;</span>
<span class="keyword">auto</span><span class="punct">*</span> p <span class="punct">=</span> sus::move<span class="punct">(</span>x<span class="punct">)</span><span class="punct">.</span>into_raw<span class="punct">(</span><span class="punct">)</span><span class="punct">;</span>
<span class="keyword">delete</span> p<span class="punct">;</span>
</code></pre>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L434">source</a></div><a name="method.leak"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.leak">leak</a>() && -> T&</div>
</div>
</div>
<div class="description long">
<p>Consumes and leaks the <code>Box</code>, returning a mutable reference, <code>T&</code>. Note
that the type T must outlive the returned reference.</p>
<p>This function is mainly useful for data that lives for the remainder of
the program's life. Dropping the returned reference will cause a memory
leak. If this is not acceptable, the reference should first be wrapped
with the <a href="sus-boxed-Box.html#method.from_raw"><code>Box::from_raw</code></a> method producing a
<code>Box</code>. This <code>Box</code> can then be dropped which will properly destroy <code>T</code> and
release the allocated memory.</p>
<p>This method is not functionally different than <a href="sus-boxed-Box.html#method.into_raw"><code>into_raw</code></a> but expresses a different intent, and returns
a reference type indicating it can not ever return null.</p>
<p>Note: unlike with the Rust <a href="https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#method.leak"><code>Box::leak</code></a>
this is not a static method, since <code>Box</code> can not expose the inner type's
methods directly in C++.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L619">source</a></div><a name="method.next"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.next">next</a>() -> auto<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::iter::IteratorAny<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Implements <a href="sus-iter-Iterator.html"><code>Iterator</code></a> if <code>T</code> is an <a href="sus-iter-Iterator.html"><code>Iterator</code></a>, forwarding through to the inner <code>T</code> object.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L634">source</a></div><a name="method.next_back"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.next_back">next_back</a>() -> auto<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::iter::IteratorAny<T></pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::iter::DoubleEndedIterator<T, typename T::Item></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Implements <a href="sus-iter-DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a> if
<code>T</code> is a <a href="sus-iter-DoubleEndedIterator.html"><code>DoubleEndedIterator</code></a>,
forwarding through to the inner <code>T</code> object.</p>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L626">source</a></div><a name="method.size_hint"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.size_hint">size_hint</a>() const -> <a class="type-name" href="sus-iter-SizeHint.html" title="sus::iter::SizeHint">SizeHint</a><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::iter::IteratorAny<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>Implements <a href="sus-iter-Iterator.html"><code>Iterator</code></a> if <code>T</code> is an <a href="sus-iter-Iterator.html"><code>Iterator</code></a>, forwarding through to the inner <code>T</code> object.</p>
</div>
</div>
</div>
<div class="section methods nonstatic">
<h1 class="section-header">
<a name="operators" href="#operators">Operators</a>
</h1>
<div class="section-items">
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L580">source</a></div><a name="method.operator()"></a><div class="template">template <class... Args></div><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator()">operator()</a>(Args&&... args) const& -> sus::fn::Return<T, Args...><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">T::IsDynFn</pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::fn::Fn<T, sus::fn::Return<T, Args...> (Args...)></pre></div>
</div></div>
</div>
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L580">source</a></div><a name="method.operator()"></a><div class="template">template <class... Args></div><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator()">operator()</a>(Args&&... args) & -> sus::fn::ReturnMut<T, Args...><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">T::IsDynFn</pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::fn::FnMut<T, sus::fn::ReturnMut<T, Args...> (Args...)></pre></div>
</div></div>
</div>
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L580">source</a></div><a name="method.operator()"></a><div class="template">template <class... Args></div><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator()">operator()</a>(Args&&... args) && -> sus::fn::ReturnOnce<T, Args...><div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">T::IsDynFn</pre></div>
<div class="requires-constraint"><pre class="requires-constraint-line">sus::fn::FnOnce<T, sus::fn::ReturnOnce<T, Args...> (Args...)></pre></div>
</div></div>
</div>
</div>
<div class="description long">
<p>A <code>Box</code> holding a type-erased function type will satisfy the fn concepts
and can be used as a function type. It will forward the call through
to the inner type.</p>
<ul>
<li><code>Box<</code><a href="sus-fn-DynFn.html"><code>DynFn</code></a><code>></code> satisfies <a href="sus-fn-Fn.html"><code>Fn</code></a>.</li>
<li><code>Box<</code><a href="sus-fn-DynFnMut.html"><code>DynFnMut</code></a><code>></code> satisfies
<a href="sus-fn-FnMut.html"><code>FnMut</code></a>.</li>
<li><code>Box<</code><a href="sus-fn-DynFnOnce.html"><code>DynFnOnce</code></a><code>></code> satisfies
<a href="sus-fn-FnOnce.html"><code>FnOnce</code></a>.</li>
</ul>
<p>The usual compatibility rules apply, allowing <a href="sus-fn-DynFn.html"><code>DynFn</code></a>
to be treated like <a href="sus-fn-DynFnMut.html"><code>DynFnMut</code></a>
and both of them to be treated like <a href="sus-fn-DynFnOnce.html"><code>DynFnOnce</code></a>.</p>
<p>A <code>Box<</code><a href="sus-fn-DynFnOnce.html"><code>DynFnOnce</code></a><code>></code> must be moved from
when called, and will destroy the
underlying function object after the call completes.</p>
<h1><a name="examples-1" href="#examples-1">Examples</a></h1>
<p>A <code>Box<DynFn></code> being used as a function object:</p>
<pre><code><span class="keyword">const</span> <span class="keyword">auto</span> b <span class="punct">=</span> Box<span class="punct"><</span>sus::fn::DynFn<span class="punct"><</span>usize<span class="punct">(</span>std::string_view<span class="punct">)</span><span class="punct">></span><span class="punct">></span>::from<span class="punct">(</span>
<span class="punct">&</span>std::string_view::size<span class="punct">)</span><span class="punct">;</span>
sus_check<span class="punct">(</span>b<span class="punct">(</span><span class="string">"hello world"</span><span class="punct">)</span> <span class="punct">=</span><span class="punct">=</span> 11u<span class="punct">)</span><span class="punct">;</span>
<span class="keyword">auto</span> mut_b <span class="punct">=</span> Box<span class="punct"><</span>sus::fn::DynFn<span class="punct"><</span>usize<span class="punct">(</span>std::string_view<span class="punct">)</span><span class="punct">></span><span class="punct">></span>::from<span class="punct">(</span>
<span class="punct">&</span>std::string_view::size<span class="punct">)</span><span class="punct">;</span>
sus_check<span class="punct">(</span>mut_b<span class="punct">(</span><span class="string">"hello world"</span><span class="punct">)</span> <span class="punct">=</span><span class="punct">=</span> 11u<span class="punct">)</span><span class="punct">;</span>
sus_check<span class="punct">(</span>sus::move<span class="punct">(</span>mut_b<span class="punct">)</span><span class="punct">(</span><span class="string">"hello world"</span><span class="punct">)</span> <span class="punct">=</span><span class="punct">=</span> 11u<span class="punct">)</span><span class="punct">;</span>
<span class="comment">// The object inside `mut_b` is now destroyed.</span>
</code></pre>
<p>A <code>Box<DynFnMut></code> being used as a function object. It can not be called
on a <code>const Box</code> as it requies the ability to mutate, and <code>const Box</code>
treats its inner object as const:</p>
<pre><code><span class="keyword">auto</span> mut_b <span class="punct">=</span> Box<span class="punct"><</span>sus::fn::DynFnMut<span class="punct"><</span>usize<span class="punct">(</span>std::string_view<span class="punct">)</span><span class="punct">></span><span class="punct">></span>::from<span class="punct">(</span>
<span class="punct">&</span>std::string_view::size<span class="punct">)</span><span class="punct">;</span>
sus_check<span class="punct">(</span>mut_b<span class="punct">(</span><span class="string">"hello world"</span><span class="punct">)</span> <span class="punct">=</span><span class="punct">=</span> 11u<span class="punct">)</span><span class="punct">;</span>
sus_check<span class="punct">(</span>sus::move<span class="punct">(</span>mut_b<span class="punct">)</span><span class="punct">(</span><span class="string">"hello world"</span><span class="punct">)</span> <span class="punct">=</span><span class="punct">=</span> 11u<span class="punct">)</span><span class="punct">;</span>
<span class="comment">// The object inside `mut_b` is now destroyed.</span>
</code></pre>
<p>A <code>Box<DynFnOnce></code> being used as a function object. It must be an rvalue
(either a return from a call or moved with <a href="sus-mem-fn.move.html"><code>move</code></a>)
to call through it:</p>
<pre><code><span class="keyword">auto</span> b <span class="punct">=</span> Box<span class="punct"><</span>sus::fn::DynFnOnce<span class="punct"><</span>usize<span class="punct">(</span>std::string_view<span class="punct">)</span><span class="punct">></span><span class="punct">></span>::from<span class="punct">(</span>
<span class="punct">&</span>std::string_view::size<span class="punct">)</span><span class="punct">;</span>
sus_check<span class="punct">(</span>sus::move<span class="punct">(</span>b<span class="punct">)</span><span class="punct">(</span><span class="string">"hello world"</span><span class="punct">)</span> <span class="punct">=</span><span class="punct">=</span> 11u<span class="punct">)</span><span class="punct">;</span>
<span class="keyword">auto</span> x <span class="punct">=</span> <span class="punct">[</span><span class="punct">]</span> <span class="punct">{</span>
<span class="keyword">return</span> Box<span class="punct"><</span>sus::fn::DynFnOnce<span class="punct"><</span>usize<span class="punct">(</span>std::string_view<span class="punct">)</span><span class="punct">></span><span class="punct">></span>::from<span class="punct">(</span>
<span class="punct">&</span>std::string_view::size<span class="punct">)</span><span class="punct">;</span>
<span class="punct">}</span><span class="punct">;</span>
sus_check<span class="punct">(</span>x<span class="punct">(</span><span class="punct">)</span><span class="punct">(</span><span class="string">"hello world"</span><span class="punct">)</span> <span class="punct">=</span><span class="punct">=</span> 11u<span class="punct">)</span><span class="punct">;</span>
</code></pre>
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L272">source</a></div><a name="method.operator*"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator*">operator*</a>() const -> <span class="const">const</span> T&</div>
</div>
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L272">source</a></div><a name="method.operator*"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator*">operator*</a>() -> T&<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">!std::is_const_v<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L283">source</a></div><a name="method.operator->"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator->">operator-></a>() const -> <span class="const">const</span> T*</div>
</div>
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L283">source</a></div><a name="method.operator->"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator->">operator-></a>() -> T*<div class="requires">
<span class="requires-keyword keyword">
requires
</span>
<div class="requires-constraint"><pre class="requires-constraint-line">!std::is_const_v<T></pre></div>
</div></div>
</div>
</div>
<div class="description long">
</div>
<div class="overload-set item-name">
<div class="overload">
<div class="function-signature"><div class="src rightside"><a href="https://github.com/chromium/subspace/blob/main/sus/boxed/box.h#L259">source</a></div><a name="method.operator=.move"></a><span class="function-auto">auto</span> <a class="function-name" href="sus-boxed-Box.html#method.operator=.move">operator=</a>(<a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T>&& rhs) -> <a class="type-name" href="sus-boxed-Box.html" title="sus::boxed::Box">Box</a><T>&</div>
</div>
</div>
<div class="description long">
<p>Satisifes the <a href="sus-mem-Move.html"><code>Move</code></a> concept for