Skip to content

Instantly share code, notes, and snippets.

@Siapran
Last active February 6, 2020 19:11
Show Gist options
  • Save Siapran/08ebeb0dc5e8070da435ab8dbf74dcdc to your computer and use it in GitHub Desktop.
Save Siapran/08ebeb0dc5e8070da435ab8dbf74dcdc to your computer and use it in GitHub Desktop.
struct VolumeVolumeRegistration;
struct VolumeTree {
Volume volume;
std::vector<VolumeVolumeRegistration> children;
size_t depth = 0;
};
struct VolumeVolumeRegistration {
Transform transform;
VolumeTree tree;
};
// [...]
auto volumeLensAt(VolumeTree tree, int &index)
-> std::optional<std::decay_t<decltype(lager::lens::attr(&VolumeTree::volume))>>
{
using namespace lager::lens;
if (index == 0) {
return attr(&VolumeTree::volume);
} else {
size_t i = 0;
for (auto child : tree.children) {
--index;
auto resLens = volumeLensAt(child.tree, index);
if (resLens.has_value()) {
return attr(&VolumeTree::children)
| at(i)
| attr(&VolumeVolumeRegistration::tree)
| resLens.value();
}
++i;
}
return std::nullopt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment