Skip to content
Snippets Groups Projects
Commit 33a82e60 authored by Whitney Armstrong's avatar Whitney Armstrong
Browse files

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
...@@ -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";
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment