Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
func_var_pattern
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Whitney Armstrong
func_var_pattern
Commits
33a82e60
Commit
33a82e60
authored
6 years ago
by
Whitney Armstrong
Browse files
Options
Downloads
Patches
Plain Diff
Added example for using a struct instead of pod
modified: func_pattern.cxx
parent
9891ae89
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
func_pattern.cxx
+30
-13
30 additions, 13 deletions
func_pattern.cxx
with
30 additions
and
13 deletions
func_pattern.cxx
+
30
−
13
View file @
33a82e60
...
@@ -222,6 +222,16 @@ namespace func {
...
@@ -222,6 +222,16 @@ namespace func {
}
// namespace func
}
// namespace func
struct
XYZ_vec
{
double
x
=
0.0
;
double
y
=
0.0
;
double
z
=
0.0
;
};
template
<
typename
Tag
>
using
Vec_Var
=
NamedType
<
XYZ_vec
,
Tag
>
;
int
main
()
{
int
main
()
{
using
namespace
func
;
using
namespace
func
;
...
@@ -236,8 +246,13 @@ int main() {
...
@@ -236,8 +246,13 @@ int main() {
using
E_coord
=
Var
<
struct
E_coord_tag
>
;
using
E_coord
=
Var
<
struct
E_coord_tag
>
;
using
F_coord
=
Var
<
struct
F_coord_tag
>
;
using
F_coord
=
Var
<
struct
F_coord_tag
>
;
using
XYZ_coord
=
Vec_Var
<
struct
test_vector_variable_tag
>
;
// X_coord and Y_coord are the independent variables that must be provided
// to compute all the subsquently defined variables.
auto
vars0
=
make_independent_vars
<
X_coord
,
Y_coord
>
();
auto
vars0
=
make_independent_vars
<
X_coord
,
Y_coord
>
();
// Add Z_coord = x+y
auto
vars1
=
vars0
.
add
<
Z_coord
>
([](
const
auto
&
v
)
constexpr
{
auto
vars1
=
vars0
.
add
<
Z_coord
>
([](
const
auto
&
v
)
constexpr
{
const
auto
&
x
=
std
::
get
<
X_coord
>
(
v
);
const
auto
&
x
=
std
::
get
<
X_coord
>
(
v
);
const
auto
&
y
=
std
::
get
<
Y_coord
>
(
v
);
const
auto
&
y
=
std
::
get
<
Y_coord
>
(
v
);
...
@@ -264,20 +279,7 @@ int main() {
...
@@ -264,20 +279,7 @@ int main() {
return
1.0
/
(
x
*
y
*
z
);
return
1.0
/
(
x
*
y
*
z
);
});
});
//auto values1 = vars1.ComputeValues(std::make_tuple(X_coord{2.0}, Y_coord{3.0}));
//std::cout << std::get<0>(values1) << "\n";
//std::cout << std::get<1>(values1) << "\n";
//std::cout << std::get<2>(values1) << "\n";
//auto values2 = vars2.ComputeValues(std::make_tuple(X_coord{2.0}, Y_coord{3.0}));
//std::cout << std::get<0>(values2) << "\n";
//std::cout << std::get<1>(values2) << "\n";
//std::cout << std::get<2>(values2) << "\n";
//std::cout << " A_coord " << std::get<A_coord>(values2) << "\n";
//std::cout << " B_coord " << std::get<B_coord>(values2) << "\n";
//std::cout << " C_coord " << std::get<C_coord>(values2) << "\n";
auto
vars3
=
vars2
.
add
<
D_coord
,
E_coord
,
F_coord
>
(
auto
vars3
=
vars2
.
add
<
D_coord
,
E_coord
,
F_coord
>
(
[](
const
auto
&
v
)
constexpr
{
[](
const
auto
&
v
)
constexpr
{
...
@@ -308,6 +310,7 @@ int main() {
...
@@ -308,6 +310,7 @@ int main() {
return
c
/
(
x
*
y
*
z
);
return
c
/
(
x
*
y
*
z
);
});
});
auto
values3
=
vars3
.
ComputeValues
(
std
::
make_tuple
(
X_coord
{
2.0
},
Y_coord
{
77.0
}));
auto
values3
=
vars3
.
ComputeValues
(
std
::
make_tuple
(
X_coord
{
2.0
},
Y_coord
{
77.0
}));
//std::cout << std::get<0>(values3) << "\n";
//std::cout << std::get<0>(values3) << "\n";
...
@@ -322,5 +325,19 @@ int main() {
...
@@ -322,5 +325,19 @@ int main() {
std
::
cout
<<
std
::
get
<
D_coord
>
(
values3
)
<<
"
\n
"
;
std
::
cout
<<
std
::
get
<
D_coord
>
(
values3
)
<<
"
\n
"
;
std
::
cout
<<
std
::
get
<
E_coord
>
(
values3
)
<<
"
\n
"
;
std
::
cout
<<
std
::
get
<
E_coord
>
(
values3
)
<<
"
\n
"
;
std
::
cout
<<
std
::
get
<
F_coord
>
(
values3
)
<<
"
\n
"
;
std
::
cout
<<
std
::
get
<
F_coord
>
(
values3
)
<<
"
\n
"
;
auto
vars4
=
vars3
.
add
<
XYZ_coord
>
(
[](
const
auto
&
v
)
constexpr
{
const
auto
&
x
=
std
::
get
<
X_coord
>
(
v
);
const
auto
&
y
=
std
::
get
<
Y_coord
>
(
v
);
const
auto
&
z
=
std
::
get
<
Z_coord
>
(
v
);
return
XYZ_vec
{
x
,
y
,
z
};
});
auto
values4
=
vars4
.
ComputeValues
(
std
::
make_tuple
(
X_coord
{
2.0
},
Y_coord
{
77.0
}));
std
::
cout
<<
std
::
get
<
XYZ_coord
>
(
values4
).
get
().
x
<<
"
\n
"
;
std
::
cout
<<
std
::
get
<
XYZ_coord
>
(
values4
).
get
().
y
<<
"
\n
"
;
std
::
cout
<<
std
::
get
<
XYZ_coord
>
(
values4
).
get
().
z
<<
"
\n
"
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment