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_SAME_SIZE_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_UTIL_SAME_SIZE_HPP_INCLUDED
22 #include <boost/numeric/odeint/util/is_resizeable.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/all.hpp>
31 #include <boost/range.hpp>
38 template< typename State1 , typename State2 , class Enabler = void >
39 struct same_size_impl_sfinae
41 static bool same_size( const State1 &x1 , const State2 &x2 )
43 return ( boost::size( x1 ) == boost::size( x2 ) );
49 // standard implementation relies on boost.range
50 template< class State1 , class State2 >
53 static bool same_size( const State1 &x1 , const State2 &x2 )
55 return same_size_impl_sfinae< State1 , State2 >::same_size( x1 , x2 );
60 // do not overload or specialize this function, specialize resize_impl<> instead
61 template< class State1 , class State2 >
62 bool same_size( const State1 &x1 , const State2 &x2 )
64 return same_size_impl< State1 , State2 >::same_size( x1 , x2 );
69 struct same_size_fusion
71 typedef bool result_type;
73 template< class S1 , class S2 >
74 bool operator()( const S1 &x1 , const S2 &x2 ) const
76 return same_size_op( x1 , x2 , typename is_resizeable< S1 >::type() );
79 template< class S1 , class S2 >
80 bool same_size_op( const S1 &x1 , const S2 &x2 , boost::true_type ) const
82 return same_size( x1 , x2 );
85 template< class S1 , class S2 >
86 bool same_size_op( const S1 &/*x1*/ , const S2 &/*x2*/ , boost::false_type ) const
96 template< class FusionSeq >
97 struct same_size_impl_sfinae< FusionSeq , FusionSeq , typename boost::enable_if< typename boost::fusion::traits::is_sequence< FusionSeq >::type >::type >
99 static bool same_size( const FusionSeq &x1 , const FusionSeq &x2 )
101 typedef boost::fusion::vector< const FusionSeq& , const FusionSeq& > Sequences;
102 Sequences sequences( x1 , x2 );
103 return boost::fusion::all( boost::fusion::zip_view< Sequences >( sequences ) ,
104 boost::fusion::make_fused( detail::same_size_fusion() ) );
115 #endif // BOOST_NUMERIC_ODEINT_UTIL_SAME_SIZE_HPP_INCLUDED