Created
August 31, 2017 18:31
-
-
Save danvonk/cd7620c882aae2357a4f222497a4c1ba 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
#include <boost/hana.hpp> | |
#include <iostream> | |
template <typename T> | |
struct basic_type { | |
using type = T; | |
}; | |
namespace hana = boost::hana; | |
using namespace hana::literals; | |
int main() { | |
auto position = hana::make_pair(hana::type_c<float>, 3); | |
auto normal = hana::make_pair(hana::type_c<float>, 3); | |
auto texCoord = hana::make_pair(hana::type_c<float>, 2); | |
auto layout = hana::make_tuple(position, normal, texCoord); | |
int byteSize = 0; | |
hana::for_each(layout, [&](auto component) { | |
using T = typename decltype(+hana::first(component))::basic_type::type; | |
byteSize += (sizeof(T) * hana::second(component)); | |
}); | |
int count = 0; | |
int offset = 0; | |
hana::for_each(layout, [&](auto component) { | |
using T = typename decltype(+hana::first(component))::basic_type::type; | |
std::cout << "----\n"; | |
std::cout << "Index: " << count << "\n"; | |
std::cout << "Size: " << hana::second(component) << "\n"; | |
std::cout << "Stride: " << byteSize << "\n"; | |
std::cout << "Offset: " << offset << "\n"; | |
count++; | |
offset += (sizeof(T) * hana::second(component)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment