add common sort

This commit is contained in:
chatlanin
2023-08-14 21:11:39 +03:00
parent 1242044571
commit 86ac6b451d
5 changed files with 64 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
#pragma once
#include <algorithm>
namespace hack::algorithms
{
// общая сортировка диапозонов, ку кого-то есть своя локалная сортировка, а у кого-то
// нет. А тут чтоб не реализовывать, есть общая.
template<typename Range>
void sort_imp(Range& r, long)
{
std::sort(std::begin(r), std::end(r));
}
template<typename Range, typename = decltype(std::declval<Range&>().sort())>
auto sort_imp(Range& r, int) -> void
{
r.sort();
}
template<typename Range>
void sort(Range& r)
{
sort_imp(r, 0);
}
}

View File

@@ -6,6 +6,7 @@
#include <map>
#include <set>
#include <unordered_map>
#include <forward_list>
#include <concepts>
@@ -21,6 +22,9 @@ namespace hack::concepts
template<typename T>
concept is_set = std::same_as<T, std::set<typename T::key_type, typename T::key_compare, typename T::allocator_type>>;
template<typename T>
concept is_forward_list = std::same_as<T, std::forward_list<typename T::value_type>>;
template<typename T>
concept is_string = std::is_convertible_v<T, std::string_view>;
@@ -37,6 +41,7 @@ namespace hack::concepts
is_map<T> ||
is_tuple<T> ||
is_set<T> ||
is_forward_list<T> ||
std::is_array<T>() ||
is_string<T>), bool>() == true;

View File

@@ -99,6 +99,14 @@ namespace hack
std::cout << " }" << (count != 0 ? devider : "");
}
template<concepts::is_forward_list T>
static void print_t(const T& data)
{
std::cout << "{ ";
std::copy(data.cbegin(), data.cend(), iterators::sequence_ostream_iterator<typename T::value_type>(std::distance(data.cbegin(), data.cend()), std::cout));
std::cout << " }" << (count != 0 ? devider : "");
}
template<concepts::is_map T>
static void print_t(const T& data)
{