switch.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef BOOST_MPL_SWITCH_HPP_INCLUDED
  2. #define BOOST_MPL_SWITCH_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2003-2004
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/mpl for documentation.
  10. // $Id$
  11. // $Date$
  12. // $Revision$
  13. #include <boost/mpl/find_if.hpp>
  14. #include <boost/mpl/deref.hpp>
  15. #include <boost/mpl/lambda.hpp>
  16. #include <boost/mpl/apply.hpp>
  17. #include <boost/mpl/pair.hpp>
  18. #include <boost/mpl/aux_/na_spec.hpp>
  19. #include <boost/mpl/aux_/lambda_support.hpp>
  20. namespace boost { namespace mpl {
  21. template<
  22. typename BOOST_MPL_AUX_NA_PARAM(Body)
  23. , typename BOOST_MPL_AUX_NA_PARAM(T)
  24. >
  25. struct switch_
  26. {
  27. typedef typename find_if<
  28. Body
  29. , apply1< lambda< first<_1> >, T >
  30. >::type iter_;
  31. typedef typename deref<iter_>::type pair_;
  32. typedef typename lambda< typename second<pair_>::type >::type f_;
  33. typedef typename apply1<f_,T>::type type;
  34. BOOST_MPL_AUX_LAMBDA_SUPPORT(2,switch_,(Body,T))
  35. };
  36. BOOST_MPL_AUX_NA_SPEC(2, switch_)
  37. }}
  38. #endif // BOOST_MPL_SWITCH_HPP_INCLUDED