diff --git a/testspr/sprout/algorithm.hpp b/testspr/sprout/algorithm.hpp index 56e48d34..976fe0c4 100644 --- a/testspr/sprout/algorithm.hpp +++ b/testspr/sprout/algorithm.hpp @@ -1,107 +1,12 @@ #ifndef TESTSPR_SPROUT_ALGORITHM_HPP #define TESTSPR_SPROUT_ALGORITHM_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include namespace testspr { static void algorithm_test() { - testspr::algorithm_copy_test(); - testspr::algorithm_copy_n_test(); - testspr::algorithm_copy_if_test(); - testspr::algorithm_copy_backward_test(); - testspr::algorithm_transform_test(); - testspr::algorithm_replace_test(); - testspr::algorithm_replace_if_test(); - testspr::algorithm_replace_copy_test(); - testspr::algorithm_replace_copy_if_test(); - testspr::algorithm_fill_test(); - testspr::algorithm_fill_n_test(); - testspr::algorithm_generate_test(); - testspr::algorithm_generate_n_test(); - testspr::algorithm_remove_test(); - testspr::algorithm_remove_if_test(); - testspr::algorithm_remove_copy_test(); - testspr::algorithm_remove_copy_if_test(); - testspr::algorithm_unique_test(); - testspr::algorithm_unique_copy_test(); - testspr::algorithm_reverse_test(); - testspr::algorithm_reverse_copy_test(); - testspr::algorithm_rotate_test(); - testspr::algorithm_rotate_copy_test(); - testspr::algorithm_shuffle_test(); - testspr::algorithm_shuffle_result_test(); - testspr::algorithm_partition_test(); - testspr::algorithm_partition_copy_test(); - testspr::algorithm_stable_partition_test(); - testspr::algorithm_stable_partition_copy_test(); - testspr::algorithm_sort_test(); - testspr::algorithm_stable_sort_test(); - testspr::algorithm_partial_sort_test(); - testspr::algorithm_nth_element_test(); - testspr::algorithm_merge_test(); - testspr::algorithm_inplace_merge_test(); - testspr::algorithm_set_union_test(); - testspr::algorithm_set_intersection_test(); - testspr::algorithm_set_difference_test(); - testspr::algorithm_set_symmetric_difference_test(); - testspr::algorithm_push_heap_test(); - testspr::algorithm_pop_heap_test(); - testspr::algorithm_make_heap_test(); - testspr::algorithm_make_partial_heap_test(); - testspr::algorithm_sort_heap_test(); - testspr::algorithm_swap_element_test(); - testspr::algorithm_swap_element_copy_test(); - testspr::algorithm_bogo_sort_test(); - testspr::algorithm_bogo_sort_result_test(); + testspr::algorithm_modifying_test(); } } // namespace testspr #endif // #ifndef TESTSPR_SPROUT_ALGORITHM_HPP - diff --git a/testspr/sprout/algorithm/modifying.hpp b/testspr/sprout/algorithm/modifying.hpp new file mode 100644 index 00000000..2e6f0614 --- /dev/null +++ b/testspr/sprout/algorithm/modifying.hpp @@ -0,0 +1,106 @@ +#ifndef TESTSPR_SPROUT_ALGORITHM_MODIFYIING_HPP +#define TESTSPR_SPROUT_ALGORITHM_MODIFYIING_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace testspr { + static void algorithm_modifying_test() { + testspr::algorithm_copy_test(); + testspr::algorithm_copy_n_test(); + testspr::algorithm_copy_if_test(); + testspr::algorithm_copy_backward_test(); + testspr::algorithm_transform_test(); + testspr::algorithm_replace_test(); + testspr::algorithm_replace_if_test(); + testspr::algorithm_replace_copy_test(); + testspr::algorithm_replace_copy_if_test(); + testspr::algorithm_fill_test(); + testspr::algorithm_fill_n_test(); + testspr::algorithm_generate_test(); + testspr::algorithm_generate_n_test(); + testspr::algorithm_remove_test(); + testspr::algorithm_remove_if_test(); + testspr::algorithm_remove_copy_test(); + testspr::algorithm_remove_copy_if_test(); + testspr::algorithm_unique_test(); + testspr::algorithm_unique_copy_test(); + testspr::algorithm_reverse_test(); + testspr::algorithm_reverse_copy_test(); + testspr::algorithm_rotate_test(); + testspr::algorithm_rotate_copy_test(); + testspr::algorithm_shuffle_test(); + testspr::algorithm_shuffle_result_test(); + testspr::algorithm_partition_test(); + testspr::algorithm_partition_copy_test(); + testspr::algorithm_stable_partition_test(); + testspr::algorithm_stable_partition_copy_test(); + testspr::algorithm_sort_test(); + testspr::algorithm_stable_sort_test(); + testspr::algorithm_partial_sort_test(); + testspr::algorithm_nth_element_test(); + testspr::algorithm_merge_test(); + testspr::algorithm_inplace_merge_test(); + testspr::algorithm_set_union_test(); + testspr::algorithm_set_intersection_test(); + testspr::algorithm_set_difference_test(); + testspr::algorithm_set_symmetric_difference_test(); + testspr::algorithm_push_heap_test(); + testspr::algorithm_pop_heap_test(); + testspr::algorithm_make_heap_test(); + testspr::algorithm_make_partial_heap_test(); + testspr::algorithm_sort_heap_test(); + testspr::algorithm_swap_element_test(); + testspr::algorithm_swap_element_copy_test(); + testspr::algorithm_bogo_sort_test(); + testspr::algorithm_bogo_sort_result_test(); + } +} // namespace testspr + +#endif // #ifndef TESTSPR_SPROUT_ALGORITHM_MODIFYIING_HPP diff --git a/testspr/tools.hpp b/testspr/tools.hpp index 4519d75e..fd7cc96e 100644 --- a/testspr/tools.hpp +++ b/testspr/tools.hpp @@ -9,23 +9,13 @@ # include #endif -// -// TESTSPR_PP_CAT -// -#define TESTSPR_PP_CAT(a, b) TESTSPR_PP_CAT_I(a, b) -#define TESTSPR_PP_CAT_I(a, b) a ## b - // // TESTSPR_STATIC_ASSERT -// -#define TESTSPR_STATIC_ASSERT(expr) static_assert(expr, #expr) -// // TESTSPR_ASSERT -// -#define TESTSPR_ASSERT(expr) assert(expr) -// // TESTSPR_DOUBLE_ASSERT // +#define TESTSPR_STATIC_ASSERT(expr) static_assert(expr, #expr) +#define TESTSPR_ASSERT(expr) assert(expr) #define TESTSPR_DOUBLE_ASSERT(expr) TESTSPR_STATIC_ASSERT(expr); TESTSPR_ASSERT(expr) // @@ -39,15 +29,11 @@ // // TESTSPR_STATIC_UNCHECKED -// -#define TESTSPR_STATIC_UNCHECKED(expr) TESTSPR_STATIC_WARNING(expr) -// // TESTSPR_UNCHECKED -// -#define TESTSPR_UNCHECKED(expr) (expr) -// // TESTSPR_DOUBLE_UNCHECKED // +#define TESTSPR_STATIC_UNCHECKED(expr) TESTSPR_STATIC_WARNING(expr) +#define TESTSPR_UNCHECKED(expr) (expr) #define TESTSPR_DOUBLE_UNCHECKED(expr) TESTSPR_STATIC_UNCHECKED(expr); TESTSPR_UNCHECKED(expr) namespace testspr { @@ -56,6 +42,10 @@ namespace testspr { // template struct is_even { + public: + typedef T argument_type; + typedef bool result_type; + public: SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 == 0; } }; // @@ -63,6 +53,10 @@ namespace testspr { // template struct is_odd { + public: + typedef T argument_type; + typedef bool result_type; + public: SPROUT_CONSTEXPR bool operator()(T const& t) const { return t % 2 != 0; } }; @@ -71,6 +65,11 @@ namespace testspr { // template struct less { + public: + typedef T first_argument_type; + typedef T second_argument_type; + typedef bool result_type; + public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs < rhs; } }; // @@ -78,6 +77,11 @@ namespace testspr { // template struct greater { + public: + typedef T first_argument_type; + typedef T second_argument_type; + typedef bool result_type; + public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs > rhs; } }; // @@ -85,6 +89,11 @@ namespace testspr { // template struct equal_to { + public: + typedef T first_argument_type; + typedef T second_argument_type; + typedef bool result_type; + public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs == rhs; } }; // @@ -92,6 +101,11 @@ namespace testspr { // template struct mod_less { + public: + typedef T first_argument_type; + typedef T second_argument_type; + typedef bool result_type; + public: SPROUT_CONSTEXPR bool operator()(T const& lhs, T const& rhs) const { return lhs % mod < rhs % mod; } }; @@ -100,22 +114,32 @@ namespace testspr { // template struct x2 { + public: + typedef T argument_type; + typedef T result_type; + public: SPROUT_CONSTEXPR T operator()(T const& t) const { return t + t; } }; + // // plus // template struct plus { + public: + typedef T first_argument_type; + typedef T second_argument_type; + typedef T result_type; + public: SPROUT_CONSTEXPR T operator()(T const& lhs, T const& rhs) const { return lhs + rhs; } }; // // distance // - template - SPROUT_CONSTEXPR typename std::iterator_traits::difference_type - distance(Iterator first, Iterator last) { + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + distance(InputIterator first, InputIterator last) { return first == last ? 0 : 1 + testspr::distance(first + 1, last) ; @@ -124,8 +148,8 @@ namespace testspr { // // equal // - template - SPROUT_CONSTEXPR bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) { + template + inline SPROUT_CONSTEXPR bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2) { return first1 == last1 ? first2 == last2 : first2 == last2 ? false : !(*first1 == *first2) ? false @@ -140,8 +164,8 @@ namespace testspr { // // is_found // - template - SPROUT_CONSTEXPR bool is_found(Iterator first, Iterator last, T const& value) { + template + SPROUT_CONSTEXPR bool is_found(InputIterator first, InputIterator last, T const& value) { return first == last ? false : *first == value ? true : testspr::is_found(first + 1, last, value) @@ -155,9 +179,9 @@ namespace testspr { // // count // - template - SPROUT_CONSTEXPR typename std::iterator_traits::difference_type - count(Iterator first, Iterator last, T const& value) { + template + SPROUT_CONSTEXPR typename std::iterator_traits::difference_type + count(InputIterator first, InputIterator last, T const& value) { return first == last ? 0 : (*first == value ? 1 : 0) + testspr::count(first + 1, last, value) ; @@ -169,8 +193,15 @@ namespace testspr { } namespace detail { - template - SPROUT_CONSTEXPR bool is_permutation_impl(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Iterator1 first1_, Iterator2 first2_) + template + SPROUT_CONSTEXPR bool is_permutation_impl( + ForwardIterator1 first1, + ForwardIterator1 last1, + ForwardIterator2 first2, + ForwardIterator2 last2, + ForwardIterator1 first1_, + ForwardIterator2 first2_ + ) { return first1_ == last1 && first2_ == last2 ? true : testspr::count(first1, last1, *first1_) != testspr::count(first2, first2 + testspr::distance(first1, last1), *first1_) ? false @@ -181,8 +212,14 @@ namespace testspr { // // is_permutation // - template - SPROUT_CONSTEXPR bool is_permutation(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) { + template + SPROUT_CONSTEXPR bool is_permutation( + ForwardIterator1 first1, + ForwardIterator1 last1, + ForwardIterator2 first2, + ForwardIterator2 last2 + ) + { return testspr::detail::is_permutation_impl(first1, last1, first2, last2, first1, first2); } template