Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
VS struct_member_name
#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<typename Sig> struct result; template <typename This,typename N> struct result<This(N)> { typedef std::string type; }; template<class N> std::string operator() (N) const { return boost::fusion::extension::struct_member_name<Struct, N::value>::call(); } }; struct print { template<typename Sig> struct result; template <typename T> struct result<print(T)> { typedef void type; }; 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
Two-phase sample with VC++ 2015
zero size std::array parameter
students grade
make Derive final
decltype_lambda
Workaround for https://github.com/Project-OSRM/osrm-backend/pull/4385
What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C?
MSVC C2888 bug
hangman
IBE FT ParseFileName