resize.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 2009-2011 Karsten Ahnert
  9. Copyright 2009-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. // resize function
  28. // standard implementation relies on boost.range and resize member function
  29. template< class StateOut , class StateIn , class Enabler = void >
  30. struct resize_impl
  31. {
  32. static void resize( StateOut &x1 , const StateIn &x2 )
  33. {
  34. x1.resize( boost::size( x2 ) );
  35. }
  36. };
  37. // do not overload or specialize this function, specialize resize_impl<> instead
  38. template< class StateOut , class StateIn >
  39. void resize( StateOut &x1 , const StateIn &x2 )
  40. {
  41. resize_impl< StateOut , StateIn >::resize( x1 , x2 );
  42. }
  43. namespace detail {
  44. struct resizer
  45. {
  46. typedef void result_type;
  47. template< class StateOut , class StateIn >
  48. void operator()( StateOut &x1 , const StateIn &x2 ) const
  49. {
  50. resize_op( x1 , x2 , typename is_resizeable< StateOut >::type() );
  51. }
  52. template< class StateOut , class StateIn >
  53. void resize_op( StateOut &x1 , const StateIn &x2 , boost::true_type ) const
  54. {
  55. resize( x1 , x2 );
  56. }
  57. template< class StateOut , class StateIn >
  58. void resize_op( StateOut &x1 , const StateIn &x2 , boost::false_type ) const
  59. {
  60. }
  61. };
  62. } // namespace detail
  63. /*
  64. * specialization for fusion sequences
  65. */
  66. template< class FusionSeq >
  67. struct resize_impl< FusionSeq , FusionSeq , typename boost::enable_if< typename boost::fusion::traits::is_sequence< FusionSeq >::type >::type >
  68. {
  69. static void resize( FusionSeq &x1 , const FusionSeq &x2 )
  70. {
  71. typedef boost::fusion::vector< FusionSeq& , const FusionSeq& > Sequences;
  72. Sequences sequences( x1 , x2 );
  73. boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( detail::resizer() ) );
  74. }
  75. };
  76. }
  77. }
  78. }
  79. #endif // BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED