Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
VS struct_member_name
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#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; }
cl.exe
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 3,11 sec, absolute running time: 0,44 sec, absolute service time: 3,56 sec
fork mode
|
history
|
discussion
name id