Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
VS struct name enumerate
#include <iostream> #include <string> #include <type_traits> #include <boost/mpl/range_c.hpp> #include <boost/fusion/include/size.hpp> #include <boost/fusion/adapted/struct/define_assoc_struct.hpp> #include <boost/fusion/algorithm/iteration/for_each.hpp> #include <boost/fusion/algorithm/transformation/zip.hpp> #include <boost/fusion/algorithm/transformation/transform.hpp> namespace keys { struct name {}; struct id {}; } BOOST_FUSION_DEFINE_ASSOC_STRUCT((), Student, (std::string, name, keys::name) (int, id, keys::id) ) template <typename Struct> struct name_getter { template<class N> std::string operator() (N) const { return boost::fusion::extension::struct_member_name<Struct, N::value>::call(); } }; struct print { template<class S> void operator() (const S& i) const { std::cout << i << std::endl; } }; template <typename Struct, typename Indices=boost::mpl::range_c<unsigned, 0, boost::fusion::result_of::size<Struct>::value > > typename boost::fusion::result_of::transform<Indices const, name_getter<Struct> >::type get_names(Struct) { return boost::fusion::transform(Indices(),name_getter<Struct>()); } int main() { Student j = {"John", 42}; auto names = get_names(j); boost::fusion::for_each(names, print()); return 0; }
run
|
edit
|
history
|
help
0
Number of paths in matrix
What exactly is “broken” with Microsoft Visual C++'s two-phase template instantiation?
cv2
hangman
Fibonacci stairs
Guess a number in c++
1
лаб1
Operators overloading
infix to postfix v 1.0