find_if.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. //
  3. // Distributed under the Boost Software License,Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. #include <boost/mpl/find_if.hpp>
  12. #include <boost/mpl/vector.hpp>
  13. #include <boost/mpl/distance.hpp>
  14. #include <boost/mpl/size.hpp>
  15. #include <boost/mpl/aux_/test.hpp>
  16. #include <boost/type_traits/is_float.hpp>
  17. #include <boost/type_traits/is_same.hpp>
  18. typedef vector<int,char,long,short,char,long,double,float,char>::type types;
  19. typedef begin<types>::type first_;
  20. MPL_TEST_CASE()
  21. {
  22. typedef find_if< types, boost::is_float<_> >::type iter;
  23. MPL_ASSERT(( is_same< iter::type, double > ));
  24. MPL_ASSERT_RELATION( (mpl::distance<first_,iter>::value), ==, 6 );
  25. }
  26. MPL_TEST_CASE()
  27. {
  28. typedef find_if< types, boost::is_same<_,long> >::type iter;
  29. MPL_ASSERT(( is_same< iter::type, long > ));
  30. MPL_ASSERT_RELATION( (mpl::distance<first_,iter>::value), ==, 2 );
  31. }
  32. MPL_TEST_CASE()
  33. {
  34. typedef find_if< types, boost::is_same<_,void> >::type iter;
  35. MPL_ASSERT(( is_same< iter, end<types>::type > ));
  36. MPL_ASSERT_RELATION( (mpl::distance<first_,iter>::value), ==, size<types>::value );
  37. }