FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp11/cpp11test/src/sum_int.cpp at main · josh28x/cpp11 · GitHub
josh28x
cpp11
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp11
/
cpp11test
/
src
/
sum_int.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (29 loc) · 698 Bytes
Breadcrumbs
cpp11
/
cpp11test
/
src
/
sum_int.cpp
Copy path
File metadata and controls
36 lines (29 loc) · 698 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
#
include
<
numeric
>
#
include
"
cpp11/integers.hpp
"
[[cpp11::register]]
double
sum_int_for_
(cpp11::integers x) {
double
sum =
0
.;
R_xlen_t n = x.
size
();
for
(R_xlen_t i =
0
; i < n; ++i) {
sum += x[i];
}
return
sum;
}
[[cpp11::register]]
double
sum_int_for2_
(
SEXP
x_) {
cpp11::integers
x
(x_,
false
);
double
sum =
0
.;
R_xlen_t n = x.
size
();
for
(R_xlen_t i =
0
; i < n; ++i) {
sum += x[i];
}
return
sum;
}
[[cpp11::register]]
double
sum_int_foreach_
(cpp11::integers x) {
double
sum =
0
.;
for
(
auto
v : x) {
sum += v;
}
return
sum;
}
[[cpp11::register]]
double
sum_int_accumulate_
(cpp11::integers x) {
return
std::accumulate
(x.
cbegin
(), x.
cend
(),
0
.);
}
Back
|
FazBrowse Home
|
New Git URL