Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/mpl/begin_end.hpp>
- #include <boost/mpl/next_prior.hpp>
- #include <boost/mpl/vector.hpp>
- using namespace boost::mpl;
- namespace detail {
- template < typename Begin, typename End, typename F >
- struct static_for_each
- {
- static void call( )
- {
- typedef typename Begin::type currentType;
- F::template call< currentType >();
- static_for_each< typename next< Begin >::type, End, F >::call();
- }
- };
- template < typename End, typename F >
- struct static_for_each< End, End, F >
- {
- static void call( )
- {
- }
- };
- } // namespace detail
- template < typename Sequence, typename F >
- void static_for_each( )
- {
- typedef typename begin< Sequence >::type begin;
- typedef typename end< Sequence >::type end;
- detail::static_for_each< begin, end, F >::call();
- }
- struct Foo
- {
- static void staticMemberFunction( )
- {
- std::cout << "Foo";
- }
- };
- struct Bar
- {
- static void staticMemberFunction( )
- {
- std::cout << "Bar";
- }
- };
- struct CallStaticMemberFunction
- {
- template < typename T >
- static void call()
- {
- T::staticMemberFunction();
- }
- };
- int main()
- {
- typedef vector< Foo, Bar > sequence;
- static_for_each< sequence, CallStatic >(); // prints "FooBar"
- }
- typedef boost::mpl::vector<type1*, type2*> container;
- struct functor
- {
- template<typename T> void operator()(T*)
- {
- std::cout << "created " << typeid(T).name() << std::endl;
- }
- };
- int main()
- {
- boost::mpl::for_each<container>(functor());
- }
- #include <boost/mpl/for_each.hpp>
- #include <boost/mpl/identity.hpp>
- #include <boost/mpl/vector.hpp>
- namespace mpl = boost::mpl;
- struct DoStaticCall
- {
- template <class T>
- void operator() (mpl::identity<T>) const
- {
- T::StaticCall();
- }
- };
- class A
- {
- A() {} // private constructor
- };
- class B
- {
- B() {} // private constructor
- };
- typedef boost::mpl::vector<A,B> AB;
- int main()
- {
- boost::mpl::for_each<AB, mpl::make_identity<mpl::_> >(
- DoStaticCall()
- );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment