polygon_sort_adaptor.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright 2008 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. #ifndef BOOST_POLYGON_SORT_ADAPTOR_HPP
  8. #define BOOST_POLYGON_SORT_ADAPTOR_HPP
  9. #ifdef __ICC
  10. #pragma warning(disable:2022)
  11. #pragma warning(disable:2023)
  12. #endif
  13. #include <algorithm>
  14. //! @brief polygon_sort_adaptor default implementation that calls std::sort
  15. namespace boost {
  16. namespace polygon {
  17. template<typename iterator_type>
  18. struct dummy_to_delay_instantiation{
  19. typedef int unit_type; // default GTL unit
  20. };
  21. //! @brief polygon_sort_adaptor default implementation that calls std::sort
  22. template<typename T>
  23. struct polygon_sort_adaptor {
  24. //! @brief wrapper that mimics std::sort() function and takes
  25. // the same arguments
  26. template<typename RandomAccessIterator_Type>
  27. static void sort(RandomAccessIterator_Type _First,
  28. RandomAccessIterator_Type _Last)
  29. {
  30. std::sort(_First, _Last);
  31. }
  32. //! @brief wrapper that mimics std::sort() function overload and takes
  33. // the same arguments
  34. template<typename RandomAccessIterator_Type, typename Pred_Type>
  35. static void sort(RandomAccessIterator_Type _First,
  36. RandomAccessIterator_Type _Last,
  37. const Pred_Type& _Comp)
  38. {
  39. std::sort(_First, _Last, _Comp);
  40. }
  41. };
  42. //! @brief user level wrapper for sorting quantities
  43. template <typename iter_type>
  44. void polygon_sort(iter_type _b_, iter_type _e_)
  45. {
  46. polygon_sort_adaptor<typename dummy_to_delay_instantiation<iter_type>::unit_type>::sort(_b_, _e_);
  47. }
  48. //! @brief user level wrapper for sorting quantities that takes predicate
  49. // as additional argument
  50. template <typename iter_type, typename pred_type>
  51. void polygon_sort(iter_type _b_, iter_type _e_, const pred_type& _pred_)
  52. {
  53. polygon_sort_adaptor<typename dummy_to_delay_instantiation<iter_type>::unit_type>::sort(_b_, _e_, _pred_);
  54. }
  55. } // namespace polygon
  56. } // namespace boost
  57. #endif