same_size.hpp 3.0 KB

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