Last active
January 3, 2017 08:02
-
-
Save dtoma/f7002beed239e7ce86c231b398b6ca4a to your computer and use it in GitHub Desktop.
ideas for fix parsing/serializing
This file contains hidden or 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
// http://ldionne.com/hana-cppnow-2015/ | |
// http://boostorg.github.io/hana/ | |
// note: re-read the CppCon pres on fusion for parsing | |
// somehow hold the tag and value type in the field's type? | |
template <int Tag, typename T> | |
struct Field { T value; } | |
template <int Tag, typename T> | |
constexpr auto get_tag(field<Tag, T>&&) { return Tag; } | |
// could read ASCII in to struct then pass struct around / serialize bin out | |
struct Msg { | |
BOOST_HANA_DEFINE_STRUCT(Msg, | |
(Field<35, int>, ordType), | |
(Field<55, std::string>, symbol) | |
); | |
}; | |
// ascii to tuple<Field<>...> using spirit | |
// Msg(tuple<Field<>...> t) : ordType{get<Field<35, int>>(t)}, // ... | |
// use some typedefs to make it more readable | |
auto serialize = [](std::ostream& os, auto const& object) { | |
hana::for_each(hana::members(object), [&](auto member) { | |
os << get_tag(member) << '=' << member.value << std::endl; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment