|
45 | 45 |
|
46 | 46 | // Diagnostic selection macros |
47 | 47 |
|
48 | | -#ifdef GFX_TIMSORT_ENABLE_ASSERT |
| 48 | +#if defined(GFX_TIMSORT_ENABLE_ASSERT) || defined(GFX_TIMSORT_ENABLE_AUDIT) |
49 | 49 | # include <cassert> |
| 50 | +#endif |
| 51 | + |
| 52 | +#ifdef GFX_TIMSORT_ENABLE_ASSERT |
50 | 53 | # define GFX_TIMSORT_ASSERT(expr) assert(expr) |
51 | 54 | #else |
52 | 55 | # define GFX_TIMSORT_ASSERT(expr) ((void)0) |
53 | 56 | #endif |
54 | 57 |
|
| 58 | +#ifdef GFX_TIMSORT_ENABLE_AUDIT |
| 59 | +# define GFX_TIMSORT_AUDIT(expr) assert(expr) |
| 60 | +#else |
| 61 | +# define GFX_TIMSORT_AUDIT(expr) ((void)0) |
| 62 | +#endif |
| 63 | + |
55 | 64 | #ifdef GFX_TIMSORT_ENABLE_LOG |
56 | 65 | # include <iostream> |
57 | 66 | # define GFX_TIMSORT_LOG(expr) (std::clog << "# " << __func__ << ": " << expr << std::endl) |
@@ -712,7 +721,10 @@ void timmerge(RandomAccessIterator first, RandomAccessIterator middle, |
712 | 721 | RandomAccessIterator last, Compare compare, Projection projection) { |
713 | 722 | typedef detail::projection_compare<Compare, Projection> compare_t; |
714 | 723 | compare_t comp(std::move(compare), std::move(projection)); |
715 | | - detail::TimSort<RandomAccessIterator, compare_t>::merge(first, middle, last, std::move(comp)); |
| 724 | + GFX_TIMSORT_AUDIT(std::is_sorted(first, middle, comp) && "Precondition"); |
| 725 | + GFX_TIMSORT_AUDIT(std::is_sorted(middle, last, comp) && "Precondition"); |
| 726 | + detail::TimSort<RandomAccessIterator, compare_t>::merge(first, middle, last, comp); |
| 727 | + GFX_TIMSORT_AUDIT(std::is_sorted(first, last, comp) && "Postcondition"); |
716 | 728 | } |
717 | 729 |
|
718 | 730 | /** |
@@ -742,7 +754,8 @@ void timsort(RandomAccessIterator const first, RandomAccessIterator const last, |
742 | 754 | Compare compare, Projection projection) { |
743 | 755 | typedef detail::projection_compare<Compare, Projection> compare_t; |
744 | 756 | compare_t comp(std::move(compare), std::move(projection)); |
745 | | - detail::TimSort<RandomAccessIterator, compare_t>::sort(first, last, std::move(comp)); |
| 757 | + detail::TimSort<RandomAccessIterator, compare_t>::sort(first, last, comp); |
| 758 | + GFX_TIMSORT_AUDIT(std::is_sorted(first, last, comp) && "Postcondition"); |
746 | 759 | } |
747 | 760 |
|
748 | 761 | /** |
@@ -790,6 +803,8 @@ void timsort(RandomAccessRange &range) { |
790 | 803 |
|
791 | 804 | #undef GFX_TIMSORT_ENABLE_ASSERT |
792 | 805 | #undef GFX_TIMSORT_ASSERT |
| 806 | +#undef GFX_TIMSORT_ENABLE_AUDIT |
| 807 | +#undef GFX_TIMSORT_AUDIT |
793 | 808 | #undef GFX_TIMSORT_ENABLE_LOG |
794 | 809 | #undef GFX_TIMSORT_LOG |
795 | 810 |
|
|
0 commit comments