transform_variant.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2015.
  6. // Modifications copyright (c) 2015, Oracle and/or its affiliates.
  7. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_UTIL_TRANSFORM_VARIANT_HPP
  14. #define BOOST_GEOMETRY_UTIL_TRANSFORM_VARIANT_HPP
  15. #include <boost/mpl/transform.hpp>
  16. #include <boost/variant/variant_fwd.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. /*!
  20. \brief Meta-function that takes a Sequence type, an MPL lambda
  21. expression and an optional Inserter and returns a variant type over
  22. the same types as the initial variant type, each transformed using
  23. the lambda expression.
  24. \ingroup utility
  25. \par Example
  26. \code
  27. typedef boost::mpl::vector<int, float, long> types;
  28. typedef transform_variant<types, add_pointer<_> > transformed;
  29. typedef variant<int*, float*, long*> result;
  30. BOOST_MPL_ASSERT(( equal<result, transformed> ));
  31. \endcode
  32. */
  33. template <typename Sequence, typename Op, typename In = boost::mpl::na>
  34. struct transform_variant:
  35. make_variant_over<
  36. typename boost::mpl::transform<
  37. Sequence,
  38. Op,
  39. In
  40. >::type
  41. >
  42. {};
  43. /*!
  44. \brief Meta-function that takes a boost::variant type and an MPL lambda
  45. expression and returns a variant type over the same types as the
  46. initial variant type, each transformed using the lambda expression.
  47. \ingroup utility
  48. \par Example
  49. \code
  50. typedef variant<int, float, long> variant_type;
  51. typedef transform_variant<variant_type, add_pointer<_> > transformed;
  52. typedef variant<int*, float*, long*> result;
  53. BOOST_MPL_ASSERT(( equal<result, transformed> ));
  54. \endcode
  55. */
  56. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Op>
  57. struct transform_variant<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Op, boost::mpl::na> :
  58. make_variant_over<
  59. typename boost::mpl::transform<
  60. typename variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  61. Op
  62. >::type
  63. >
  64. {};
  65. }} // namespace boost::geometry
  66. #endif // BOOST_GEOMETRY_UTIL_TRANSFORM_VARIANT_HPP