resize.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 <type_traits>
  17. #include <boost/range.hpp>
  18. #include <boost/utility/enable_if.hpp>
  19. #include <boost/fusion/include/is_sequence.hpp>
  20. #include <boost/fusion/include/zip_view.hpp>
  21. #include <boost/fusion/include/vector.hpp>
  22. #include <boost/fusion/include/make_fused.hpp>
  23. #include <boost/fusion/include/for_each.hpp>
  24. #include <boost/numeric/odeint/util/is_resizeable.hpp>
  25. namespace boost {
  26. namespace numeric {
  27. namespace odeint {
  28. template< class StateOut , class StateIn , class Enabler = void >
  29. struct resize_impl_sfinae
  30. {
  31. static void resize( StateOut &x1 , const StateIn &x2 )
  32. {
  33. x1.resize( boost::size( x2 ) );
  34. }
  35. };
  36. // resize function
  37. // standard implementation relies on boost.range and resize member function
  38. template< class StateOut , class StateIn >
  39. struct resize_impl
  40. {
  41. static void resize( StateOut &x1 , const StateIn &x2 )
  42. {
  43. resize_impl_sfinae< StateOut , StateIn >::resize( x1 , x2 );
  44. }
  45. };
  46. // do not overload or specialize this function, specialize resize_impl<> instead
  47. template< class StateOut , class StateIn >
  48. void resize( StateOut &x1 , const StateIn &x2 )
  49. {
  50. resize_impl< StateOut , StateIn >::resize( x1 , x2 );
  51. }
  52. namespace detail {
  53. struct resizer
  54. {
  55. typedef void result_type;
  56. template< class StateOut , class StateIn >
  57. void operator()( StateOut &x1 , const StateIn &x2 ) const
  58. {
  59. resize_op( x1 , x2 , typename is_resizeable< StateOut >::type() );
  60. }
  61. template< class StateOut , class StateIn >
  62. void resize_op( StateOut &x1 , const StateIn &x2 , std::true_type ) const
  63. {
  64. resize( x1 , x2 );
  65. }
  66. template< class StateOut , class StateIn >
  67. void resize_op( StateOut &/*x1*/ , const StateIn &/*x2*/ , std::false_type ) const
  68. {
  69. }
  70. };
  71. } // namespace detail
  72. /*
  73. * specialization for fusion sequences
  74. */
  75. template< class FusionSeq >
  76. struct resize_impl_sfinae< FusionSeq , FusionSeq ,
  77. typename boost::enable_if< typename boost::fusion::traits::is_sequence< FusionSeq >::type >::type >
  78. {
  79. static void resize( FusionSeq &x1 , const FusionSeq &x2 )
  80. {
  81. typedef boost::fusion::vector< FusionSeq& , const FusionSeq& > Sequences;
  82. Sequences sequences( x1 , x2 );
  83. boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( detail::resizer() ) );
  84. }
  85. };
  86. }
  87. }
  88. }
  89. #endif // BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED