FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppfront/regression-tests/mixed-initialization-safety-2.cpp2 at main · lineCode/cppfront · GitHub
lineCode
/
cppfront
Public
forked from
hsutter/cppfront
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppfront
/
regression-tests
/
mixed-initialization-safety-2.cpp2
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (36 loc) · 897 Bytes
Breadcrumbs
cppfront
/
regression-tests
/
mixed-initialization-safety-2.cpp2
Copy path
File metadata and controls
45 lines (36 loc) · 897 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include <string>
#include <vector>
#include <mutex>
#include <cstdlib>
#include <ctime>
#include <cstdio>
fill: (
out x: std::string,
in value: std::string,
in count: int
)
[[pre: value.size() >= count, "fill: value must contain at least count elements"]]
= {
x = value.substr(0, count);
}
main: () -> int =
{
x: std::string; // note: uninitialized!
if flip_a_coin() {
x = "xyzzy";
}
else {
// fill( out x, "plugh", 40 ); // note: constructs x!
}
print_decorated(x);
}
// Print! A one-expression function body...
//
print_decorated: (x:_) = std::cout << ">> [" << x << "]\n";
// Flip a coin! Exercise <mutex> <cstdlib> <ctime> and 'as'...
//
rand_init_flag: std::once_flag = ();
flip_a_coin: () -> bool = {
std::call_once(rand_init_flag, srand, time(nullptr) as unsigned );
return std::rand()%2;
}
Back
|
FazBrowse Home
|
New Git URL