Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Reference Return Types #438

Merged
merged 7 commits into from
Oct 12, 2023
Merged

Conversation

mtao
Copy link
Collaborator

@mtao mtao commented Oct 12, 2023

Our atomic operations have prototypes like

  • EdgeMesh,Tuple -> EdgeMeshExecutorData
  • TriMesh ,Tuple-> TriMeshExecutorData
  • TetMesh ,Tuple-> TetMeshExecutorData

These need to be stored during the entire multimesh traversal so that compound operations can extract information from the last operation on any particular mesh. Because this involves different input and output types it's better to use std::variant - but the input types are all references so some manipulation around std::reference_wrapper is needed. This PR provides a somewhat ugly interface that will be kept internal for executing on generic variants.

A key function here is the implied ability to call as_variant<Traits>(Mesh&) that returns a std::variant<EdgeMesh&,TriMesh&,TetMesh&> so we can just call

// assume as_mesh_variant aliases to as_variant<MeshVarTraits>
Mesh m = ...;
auto mesh_ref_var = as_mesh_variant(mesh);

std::visit([&]template <typename T>(const T& mesh) {
using MeshType = unwrap_ref_t<T>;
if constexpr(std::is_same_v<MeshType, TriMesh>) {
// do tri mesh specific things
}
}, mesh_var);

If we use Functor classes (as seen in unit tests) then users can create custom multimesh visitors using functor structs + polymorphism and even cache the return types.

@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #438 (352c905) into main (cadf64c) will increase coverage by 0.76%.
Report is 64 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #438      +/-   ##
==========================================
+ Coverage   81.95%   82.71%   +0.76%     
==========================================
  Files         154      160       +6     
  Lines        4162     4496     +334     
==========================================
+ Hits         3411     3719     +308     
- Misses        751      777      +26     
Flag Coverage Δ
wildmeshing 82.71% <100.00%> (+0.76%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...programming/ReferenceWrappedFunctorReturnCache.hpp 100.00% <100.00%> (ø)
src/wmtk/utils/metaprogramming/as_variant.hpp 100.00% <100.00%> (ø)

... and 7 files with indirect coverage changes

@mtao mtao force-pushed the mtao/base_variant branch from c9c9164 to 7b868cc Compare October 12, 2023 19:38
@mtao mtao force-pushed the mtao/base_variant branch from 7b868cc to 352c905 Compare October 12, 2023 19:46
@mtao mtao merged commit 4185fa6 into wildmeshing:main Oct 12, 2023
@mtao mtao deleted the mtao/base_variant branch October 12, 2023 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant