4444
4545// Diagnostic selection macros
4646
47- #ifdef GFX_TIMSORT_ENABLE_ASSERT
47+ #if defined( GFX_TIMSORT_ENABLE_ASSERT) || defined(GFX_TIMSORT_ENABLE_AUDIT)
4848# include < cassert>
49+ #endif
50+
51+ #ifdef GFX_TIMSORT_ENABLE_ASSERT
4952# define GFX_TIMSORT_ASSERT (expr ) assert (expr)
5053#else
5154# define GFX_TIMSORT_ASSERT (expr ) ((void )0 )
5255#endif
5356
57+ #ifdef GFX_TIMSORT_ENABLE_AUDIT
58+ # define GFX_TIMSORT_AUDIT (expr ) assert (expr)
59+ #else
60+ # define GFX_TIMSORT_AUDIT (expr ) ((void )0 )
61+ #endif
62+
5463#ifdef GFX_TIMSORT_ENABLE_LOG
5564# include < iostream>
5665# define GFX_TIMSORT_LOG (expr ) (std::clog << " # " << __func__ << " : " << expr << std::endl)
@@ -770,7 +779,10 @@ void timmerge(RandomAccessIterator first, RandomAccessIterator middle,
770779 RandomAccessIterator last, Compare compare, Projection projection) {
771780 typedef detail::projection_compare<Compare, Projection> compare_t ;
772781 compare_t comp (compare, projection);
782+ GFX_TIMSORT_AUDIT (std::is_sorted (first, middle, comp) && " Precondition" );
783+ GFX_TIMSORT_AUDIT (std::is_sorted (middle, last, comp) && " Precondition" );
773784 detail::TimSort<RandomAccessIterator, compare_t >::merge (first, middle, last, comp);
785+ GFX_TIMSORT_AUDIT (std::is_sorted (first, last, comp) && " Postcondition" );
774786}
775787
776788/* *
@@ -801,6 +813,7 @@ void timsort(RandomAccessIterator const first, RandomAccessIterator const last,
801813 typedef detail::projection_compare<Compare, Projection> compare_t ;
802814 compare_t comp (compare, projection);
803815 detail::TimSort<RandomAccessIterator, compare_t >::sort (first, last, comp);
816+ GFX_TIMSORT_AUDIT (std::is_sorted (first, last, comp) && " Postcondition" );
804817}
805818
806819/* *
@@ -824,6 +837,8 @@ void timsort(RandomAccessIterator const first, RandomAccessIterator const last)
824837
825838#undef GFX_TIMSORT_ENABLE_ASSERT
826839#undef GFX_TIMSORT_ASSERT
840+ #undef GFX_TIMSORT_ENABLE_AUDIT
841+ #undef GFX_TIMSORT_AUDIT
827842#undef GFX_TIMSORT_ENABLE_LOG
828843#undef GFX_TIMSORT_LOG
829844#undef GFX_TIMSORT_MOVE
0 commit comments