3 boost/numeric/odeint/util/state_wrapper.hpp
6 State wrapper for the state type in all stepper. The state wrappers are responsible for construction,
7 destruction, copying construction, assignment and resizing.
10 Copyright 2011-2013 Karsten Ahnert
11 Copyright 2011 Mario Mulansky
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED
22 #include <boost/range.hpp>
24 #include <boost/utility/enable_if.hpp>
25 #include <boost/fusion/include/is_sequence.hpp>
26 #include <boost/fusion/include/zip_view.hpp>
27 #include <boost/fusion/include/vector.hpp>
28 #include <boost/fusion/include/make_fused.hpp>
29 #include <boost/fusion/include/for_each.hpp>
31 #include <boost/numeric/odeint/util/is_resizeable.hpp>
38 template< class StateOut , class StateIn , class Enabler = void >
39 struct resize_impl_sfinae
41 static void resize( StateOut &x1 , const StateIn &x2 )
43 x1.resize( boost::size( x2 ) );
48 // standard implementation relies on boost.range and resize member function
49 template< class StateOut , class StateIn >
52 static void resize( StateOut &x1 , const StateIn &x2 )
54 resize_impl_sfinae< StateOut , StateIn >::resize( x1 , x2 );
59 // do not overload or specialize this function, specialize resize_impl<> instead
60 template< class StateOut , class StateIn >
61 void resize( StateOut &x1 , const StateIn &x2 )
63 resize_impl< StateOut , StateIn >::resize( x1 , x2 );
71 typedef void result_type;
73 template< class StateOut , class StateIn >
74 void operator()( StateOut &x1 , const StateIn &x2 ) const
76 resize_op( x1 , x2 , typename is_resizeable< StateOut >::type() );
79 template< class StateOut , class StateIn >
80 void resize_op( StateOut &x1 , const StateIn &x2 , boost::true_type ) const
85 template< class StateOut , class StateIn >
86 void resize_op( StateOut &/*x1*/ , const StateIn &/*x2*/ , boost::false_type ) const
95 * specialization for fusion sequences
97 template< class FusionSeq >
98 struct resize_impl_sfinae< FusionSeq , FusionSeq ,
99 typename boost::enable_if< typename boost::fusion::traits::is_sequence< FusionSeq >::type >::type >
101 static void resize( FusionSeq &x1 , const FusionSeq &x2 )
103 typedef boost::fusion::vector< FusionSeq& , const FusionSeq& > Sequences;
104 Sequences sequences( x1 , x2 );
105 boost::fusion::for_each( boost::fusion::zip_view< Sequences >( sequences ) , boost::fusion::make_fused( detail::resizer() ) );
118 #endif // BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_INCLUDED