diff --git a/.gitignore b/.gitignore index 85151b9..1e66285 100755 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,3 @@ build .cache subprojects/* !subprojects/catch2.wrap -bin/test - diff --git a/bin/audio.cpp b/bin/examples/audio/main.cpp similarity index 95% rename from bin/audio.cpp rename to bin/examples/audio/main.cpp index 0040303..f5c7b9a 100644 --- a/bin/audio.cpp +++ b/bin/examples/audio/main.cpp @@ -26,7 +26,7 @@ auto main(int argc, char *argv[]) -> int hack::audio::play(melody, sample_rate); hack::log()("Запись последовательности нот масива в файл"); - std::string file = "/mnt/raid/projects/hack/hack/bin/test/note.wav"; + std::string file = "/mnt/raid/projects/hack/hack/bin/examples/audio/note.wav"; hack::audio::save(file, melody, sample_rate); hack::log()("Воспроизведение последовательности нот из файла"); diff --git a/bin/examples/audio/note.wav b/bin/examples/audio/note.wav new file mode 100644 index 0000000..1395884 Binary files /dev/null and b/bin/examples/audio/note.wav differ diff --git a/bin/examples/concepts/main.cpp b/bin/examples/concepts/main.cpp new file mode 100644 index 0000000..894324b --- /dev/null +++ b/bin/examples/concepts/main.cpp @@ -0,0 +1,264 @@ +#include "hack/concepts/concepts.hpp" +#include "hack/logger/logger.hpp" + +template +void example_has_value_type(const T& container) +{ + hack::log()("Value type: ", typeid(typename T::value_type).name()); +} + +// template +// void example_has_key_type(const T& container) { +// std::cout << "Key type: " << typeid(typename T::key_type).name() << std::endl; +// } +// +// template +// void example_has_mapped_type(const T& container) { +// std::cout << "Mapped type: " << typeid(typename T::mapped_type).name() << std::endl; +// } +// +// template +// void example_has_iterator(const T& container) { +// std::cout << "Container is iterable, size: " << std::distance(container.begin(), container.end()) << std::endl; +// } +// +// template +// void example_has_size(const T& container) { +// std::cout << "Container size: " << container.size() << std::endl; +// } +// +// template +// void example_is_string(const T& str) { +// std::cout << "String content: " << str << " (length: " << str.length() << ")" << std::endl; +// } +// +// template +// void example_is_sequence_container(const T& container) { +// std::cout << "Sequence container with " << container.size() << " elements" << std::endl; +// } +// +// template +// void example_is_random_access_container(T& container) { +// if (!container.empty()) { +// std::cout << "First element: " << container[0] << std::endl; +// } +// } +// +// template +// void example_is_container_adapter(T& adapter) { +// std::cout << "Container adapter with " << adapter.size() << " elements" << std::endl; +// } +// +// template +// void example_is_associative_container(const T& container) { +// std::cout << "Associative container with " << container.size() << " elements" << std::endl; +// } +// +// template +// void example_is_unordered_associative_container(const T& container) { +// std::cout << "Unordered associative container with " << container.size() << " elements" << std::endl; +// } +// +// template +// void example_is_tuple_like(const T& tuple) { +// std::cout << "Tuple-like with " << std::tuple_size_v << " elements" << std::endl; +// } +// +// template +// void example_is_fixed_array(const T& array) { +// std::cout << "Fixed array with " << std::extent_v << " elements" << std::endl; +// } +// +// template> T> +// void example_is_std_array(const T& array) { +// std::cout << "std::array with " << array.size() << " elements" << std::endl; +// } +// +// template +// void example_is_any_container(const T& container) { +// std::cout << "Any container with " << container.size() << " elements" << std::endl; +// } +// +// template +// void example_is_iterable(const T& iterable) { +// std::cout << "Iterable object: "; +// for (const auto& item : iterable) { +// std::cout << item << " "; +// } +// std::cout << std::endl; +// } +// +// template +// void example_is_sized(const T& sized) { +// if constexpr (hack::concepts::modern::has_size) { +// std::cout << "Sized object: " << sized.size() << " elements" << std::endl; +// } else { +// std::cout << "Sized object (compile-time size)" << std::endl; +// } +// } +// +// template +// void example_has_key_value_semantics(T& container) { +// if constexpr (hack::concepts::modern::has_mapped_type) { +// std::cout << "Key-value container, sample access demonstrated" << std::endl; +// } else { +// std::cout << "Set-like container" << std::endl; +// } +// } +// +// template +// void example_is_contiguous_container(const T& container) { +// std::cout << "Contiguous memory container" << std::endl; +// } +// +// template, int> Container> +// void example_can_emplace(Container& container, int value) { +// container.emplace_back(value); +// std::cout << "Emplaced value: " << value << std::endl; +// } +// +// template, int> Container> +// void example_can_push_back(Container& container, int value) { +// container.push_back(value); +// std::cout << "Pushed back value: " << value << std::endl; +// } +// +// template, int> Container> +// void example_can_push_front(Container& container, int value) { +// container.push_front(value); +// std::cout << "Pushed front value: " << value << std::endl; +// } +// +// template, int> Container> +// void example_can_find(Container& container, int value) { +// auto it = container.find(value); +// if (it != container.end()) { +// std::cout << "Found value: " << value << std::endl; +// } else { +// std::cout << "Value not found: " << value << std::endl; +// } +// } +// +// // Функция для демонстрации not_supported +// template +// void check_support(const T& value) { +// if constexpr (modern::concepts::not_supported) { +// std::cout << "Type is NOT supported by this library" << std::endl; +// } else { +// std::cout << "Type is supported" << std::endl; +// } +// } + +auto main(int argc, char *argv[]) -> int +{ + // Базовые концепты + std::vector vec = { 1, 2, 3 }; + std::map map = {{ 1, "one" }, { 2, "two" }}; + int a = 10; + + hack::log()("has_value_type:"); + example_has_value_type(vec); + // example_has_value_type(a); // выдаст ошибку т.к. у a нет встроенного value_type + + // std::cout << "2. has_key_type: "; + // example_has_key_type(map); + // + // std::cout << "3. has_mapped_type: "; + // example_has_mapped_type(map); + // + // std::cout << "4. has_iterator: "; + // example_has_iterator(vec); + // + // std::cout << "5. has_size: "; + // example_has_size(vec); + // + // // Строки и контейнеры + // std::string str = "Hello"; + // std::list list = {1.1, 2.2, 3.3}; + // std::deque deque = {'a', 'b', 'c'}; + // + // std::cout << "6. is_string: "; + // example_is_string(str); + // + // std::cout << "7. is_sequence_container (vector): "; + // example_is_sequence_container(vec); + // + // std::cout << "8. is_sequence_container (list): "; + // example_is_sequence_container(list); + // + // std::cout << "9. is_random_access_container: "; + // example_is_random_access_container(vec); + // + // // Адаптеры и ассоциативные контейнеры + // std::stack stack; + // stack.push(1); stack.push(2); + // + // std::set set = {5, 3, 1, 4, 2}; + // std::unordered_map umap = {{1, "uno"}, {2, "dos"}}; + // + // std::cout << "10. is_container_adapter: "; + // example_is_container_adapter(stack); + // + // std::cout << "11. is_associative_container: "; + // example_is_associative_container(set); + // + // std::cout << "12. is_unordered_associative_container: "; + // example_is_unordered_associative_container(umap); + // + // // Кортежи и массивы + // std::tuple tuple = {1, "test", 3.14}; + // int fixed_array[5] = {1, 2, 3, 4, 5}; + // std::array std_array = {1.0f, 2.0f, 3.0f}; + // + // std::cout << "13. is_tuple_like: "; + // example_is_tuple_like(tuple); + // + // std::cout << "14. is_fixed_array: "; + // example_is_fixed_array(fixed_array); + // + // std::cout << "15. is_std_array: "; + // example_is_std_array(std_array); + // + // // Универсальные концепты + // std::cout << "16. is_any_container: "; + // example_is_any_container(vec); + // + // std::cout << "17. is_iterable: "; + // example_is_iterable(vec); + // + // std::cout << "18. is_sized: "; + // example_is_sized(vec); + // + // std::cout << "19. has_key_value_semantics: "; + // example_has_key_value_semantics(map); + // + // std::cout << "20. is_contiguous_container: "; + // example_is_contiguous_container(vec); + // + // // Концепты для алгоритмов + // std::cout << "21. can_emplace: "; + // example_can_emplace(vec, 42); + // + // std::cout << "22. can_push_back: "; + // example_can_push_back(vec, 99); + // + // std::cout << "23. can_push_front: "; + // example_can_push_front(list, 0); + // + // std::cout << "24. can_find: "; + // example_can_find(set, 3); + // + // // Проверка неподдерживаемых типов + // struct CustomType { int x; }; + // CustomType custom; + // + // std::cout << "25. not_supported check (int): "; + // check_support(42); + // + // std::cout << "26. not_supported check (CustomType): "; + // check_support(custom); + // + // std::cout << "\n=== Все примеры выполнены ===" << std::endl; + + return 0; +} diff --git a/bin/meson.build b/bin/meson.build index 0f67741..3ea4194 100755 --- a/bin/meson.build +++ b/bin/meson.build @@ -1,6 +1,7 @@ executable( meson.project_name(), - 'audio.cpp', + # 'examples/audio/main.cpp', + 'examples/concepts/main.cpp', dependencies : deps, cpp_args: args, include_directories : inc