Last active
February 6, 2020 19:11
-
-
Save Siapran/08ebeb0dc5e8070da435ab8dbf74dcdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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