resize.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/util/state_wrapper.hpp
  4. [begin_description]
  5. State wrapper for the state type in all stepper. The state wrappers are responsible for construction,
  6. destruction, copying construction, assignment and resizing.
  7. [end_description]
  8. Copyright 2011-2013 Karsten Ahnert
  9. Copyright 2011 Mario Mulansky
  10. Distributed under the Boost Software License, Version 1.0.
  11. (See accompanying file LICENSE_1_0.txt or
  12. copy at http://www.boost.org/LICENSE_1_0.txt)
  13. */
  14. #ifndef BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED
  15. #define BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED
  16. #include <boost/range.hpp>
  17. #include <boost/utility/enable_if.hpp>
  18. #include <boost/fusion/include/is_sequence.hpp>
  19. #include <boost/fusion/include/zip_view.hpp>
  20. #include <boost/fusion/include/vector.hpp>
  21. #include <boost/fusion/include/make_fused.hpp>
  22. #include <boost/fusion/include/for_each.hpp>
  23. #include <boost/numeric/odeint/util/is_resizeable.hpp>
  24. namespace boost {
  25. namespace numeric {
  26. namespace odeint {
  27. template< class StateOut , class StateIn , class Enabler = void >
  28. struct resize_impl_sfinae
  29. {
  30. static void resize( StateOut &x1 , const StateIn &x2 )
  31. {
  32. x1.resize( boost::size( x2 ) );
  33. }
  34. };
  35. // resize function
  36. // standard implementation relies on boost.range and resize member function
  37. template< class StateOut , class StateIn >
  38. struct resize_impl
  39. {
  40. static void resize( StateOut &x1 , const StateIn &x2 )
  41. {
  42. resize_impl_sfinae< StateOut , StateIn >::resize( x1 , x2 );
  43. }
  44. };
  45. // do not overload or specialize this function, specialize resize_impl<> instead
  46. template< class StateOut , class StateIn >
  47. void resize( StateOut &x1 , const StateIn &x2 )
  48. {
  49. resize_impl< StateOut , StateIn >::resize( x1 , x2 );
  50. }
  51. namespace detail {
  52. struct resizer
  53. {
  54. typedef void result_type;
  55. template< class StateOut , class StateIn >
  56. void operator()( StateOut &x1 , const StateIn &x2 ) const
  57. {
  58. resize_op( x1 , x2 , typename is_resizeable< StateOut >::type() );
  59. }
  60. template< class StateOut , class StateIn >
  61. void resize_op( StateOut &x1 , const StateIn &x2 , boost::true_type ) const
  62. {
  63. resize( x1 , x2 );
  64. }
  65. template< class StateOut , class StateIn >
  66. void resize_op( StateOut &/*x1*/ , const StateIn &/*x2*/ , boost::false_type ) const
  67. {
  68. }
  69. };
  70. } // namespace detail
  71. /*
  72. * specialization for fusion sequences
  73. */
  74. template< class FusionSeq >
  75. struct resize_impl_sfinae< FusionSeq , FusionSeq ,
  76. typename boost::enable_if< typename boost::fusion::traits::is_sequence< FusionSeq >::type >::type >
  77. {
  78. static void resize( FusionSeq &x1 , const FusionSeq &x2 )
  79. {
  80. typedef boost::fusion::vector< FusionSeq& , const FusionSeq& > Sequences;
  81. Sequences sequences( x1 , x2 );
  82. boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( detail::resizer() ) );
  83. }
  84. };
  85. }
  86. }
  87. }
  88. #endif // BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED