add is_unordered_set concept

This commit is contained in:
chatlanin 2023-08-20 10:07:06 +03:00
parent 9805cdf6cf
commit c722357baf
5 changed files with 31 additions and 4 deletions

View File

@ -1,4 +1,5 @@
#include <set>
#include <unordered_set>
#include "hack/logger/logger.hpp"
#include "hack/concepts/concepts.hpp"
@ -15,6 +16,12 @@ void test_associative(const T& m)
hack::log()("is associative", m);
}
template<hack::concepts::is_unordered_set T>
void test_unordered_set(const T& m)
{
hack::log()("is unordered set", m);
}
auto main(int argc, char *argv[]) -> int
{
std::map<std::string, int> m { { "a", 1 }, { "b", 2 } };
@ -26,6 +33,10 @@ auto main(int argc, char *argv[]) -> int
std::vector<int> v { 1, 2, 3 };
// test_associative(v); error !!!
std::unordered_set<int> us { 1, 2, 3 };
test_unordered_set(us);
test_associative(us);
}

View File

@ -1,4 +1,5 @@
#include <set>
#include <unordered_set>
#include "hack/logger/logger.hpp"
@ -9,6 +10,8 @@ auto main(int argc, char *argv[]) -> int
std::vector<int> v { 1, 2, 3 };
hack::log()(v, s);
std::unordered_set<int> us { 1, 2, 3 };
hack::log()(v, s, us);
}

View File

@ -1,6 +1,6 @@
executable(
'hack',
'utils/main.cpp',
'logger/main.cpp',
dependencies : deps,
cpp_args: args,
include_directories : inc

View File

@ -5,6 +5,7 @@
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
@ -22,6 +23,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_unordered_set = std::same_as<T, std::unordered_set<typename T::key_type>>;
template<typename T>
concept is_forward_list = std::same_as<T, std::forward_list<typename T::value_type>>;
@ -32,7 +36,7 @@ namespace hack::concepts
concept is_sequence_container = std::same_as<T, std::vector<typename T::value_type>> || std::same_as<T, std::list<typename T::value_type>> || (std::is_array_v<T> && N > 0);
template<typename T>
concept is_associative_container = is_map<T> || is_tuple<T> || is_set<T>;
concept is_associative_container = is_map<T> || is_tuple<T> || is_set<T> || is_unordered_set<T>;
template<typename T>
@ -41,6 +45,7 @@ namespace hack::concepts
is_map<T> ||
is_tuple<T> ||
is_set<T> ||
is_unordered_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_unordered_set T>
static void print_t(const T& data)
{
std::cout << "{ ";
std::copy(data.cbegin(), data.cend(), iterators::sequence_ostream_iterator<typename T::value_type>(data.size(), std::cout));
std::cout << " }" << (count != 0 ? devider : "");
}
template<concepts::is_forward_list T>
static void print_t(const T& data)
{