Skip to content

Instantly share code, notes, and snippets.

@underdoeg
Last active March 22, 2019 15:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underdoeg/4c5c616c1ad4cbb718f787eefcab902d to your computer and use it in GitHub Desktop.
Save underdoeg/4c5c616c1ad4cbb718f787eefcab902d to your computer and use it in GitHub Desktop.
#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