same_size.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_SAME_SIZE_HPP_INCLUDED
  15. #define BOOST_NUMERIC_ODEINT_UTIL_SAME_SIZE_HPP_INCLUDED
  16. #include <boost/numeric/odeint/util/is_resizeable.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/all.hpp>
  23. #include <boost/range.hpp>
  24. namespace boost {
  25. namespace numeric {
  26. namespace odeint {
  27. template< typename State1 , typename State2 , class Enabler = void >
  28. struct same_size_impl_sfinae
  29. {
  30. static bool same_size( const State1 &x1 , const State2 &x2 )
  31. {
  32. return ( boost::size( x1 ) == boost::size( x2 ) );
  33. }
  34. };
  35. // same_size function
  36. // standard implementation relies on boost.range
  37. template< class State1 , class State2 >
  38. struct same_size_impl
  39. {
  40. static bool same_size( const State1 &x1 , const State2 &x2 )
  41. {
  42. return same_size_impl_sfinae< State1 , State2 >::same_size( x1 , x2 );
  43. }
  44. };
  45. // do not overload or specialize this function, specialize resize_impl<> instead
  46. template< class State1 , class State2 >
  47. bool same_size( const State1 &x1 , const State2 &x2 )
  48. {
  49. return same_size_impl< State1 , State2 >::same_size( x1 , x2 );
  50. }
  51. namespace detail {
  52. struct same_size_fusion
  53. {
  54. typedef bool result_type;
  55. template< class S1 , class S2 >
  56. bool operator()( const S1 &x1 , const S2 &x2 ) const
  57. {
  58. return same_size_op( x1 , x2 , typename is_resizeable< S1 >::type() );
  59. }
  60. template< class S1 , class S2 >
  61. bool same_size_op( const S1 &x1 , const S2 &x2 , boost::true_type ) const
  62. {
  63. return same_size( x1 , x2 );
  64. }
  65. template< class S1 , class S2 >
  66. bool same_size_op( const S1 &/*x1*/ , const S2 &/*x2*/ , boost::false_type ) const
  67. {
  68. return true;
  69. }
  70. };
  71. } // namespace detail
  72. template< class FusionSeq >
  73. struct same_size_impl_sfinae< FusionSeq , FusionSeq , typename boost::enable_if< typename boost::fusion::traits::is_sequence< FusionSeq >::type >::type >
  74. {
  75. static bool same_size( const FusionSeq &x1 , const FusionSeq &x2 )
  76. {
  77. typedef boost::fusion::vector< const FusionSeq& , const FusionSeq& > Sequences;
  78. Sequences sequences( x1 , x2 );
  79. return boost::fusion::all( boost::fusion::zip_view< Sequences >( sequences ) ,
  80. boost::fusion::make_fused( detail::same_size_fusion() ) );
  81. }
  82. };
  83. }
  84. }
  85. }
  86. #endif // BOOST_NUMERIC_ODEINT_UTIL_SAME_SIZE_HPP_INCLUDED