Last active
March 22, 2019 15:18
-
-
Save underdoeg/4c5c616c1ad4cbb718f787eefcab902d 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 <iostream> | |
#include <brigand/brigand.hpp> | |
template<typename Members> | |
class TaggedTuple{ | |
template<typename TagType> | |
struct createMember{ | |
using type = typename TagType::type; | |
}; | |
using DataTuple = brigand::transform<Members, createMember<brigand::_1>>; | |
brigand::as_tuple<DataTuple> members; | |
public: | |
template<typename TagType> | |
auto& get(){ | |
using index = brigand::index_of<Members, TagType>; | |
return std::get<index::value>(members); | |
} | |
}; | |
int main(){ | |
struct FloatTag{ | |
using type = float; | |
}; | |
struct IntTag{ | |
using type = int; | |
}; | |
struct DoubleTag{ | |
using type = float; | |
}; | |
TaggedTuple<brigand::list<FloatTag, IntTag, DoubleTag>> tagged; | |
tagged.get<DoubleTag>() = 200; | |
auto val = tagged.get<DoubleTag>(); | |
std::cout << val << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment