diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fa1489..061c4a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,11 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +set( + CMAKE_EXPORT_COMPILE_COMMANDS + ON +) + find_package(Catch2 REQUIRED) add_executable(typelist_utils test/main.cpp test/test_utils.cpp test/test_sort.cpp) diff --git a/README.md b/README.md index a4388d5..31a9355 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# typelist_utils +# typelist_utils, a metaprogramming library [![Build and Test Package](https://github.com/cpp-playground/typelist-utils/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/cpp-playground/typelist-utils/actions/workflows/build_and_test.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=cpp-playground_typelist-utils&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=cpp-playground_typelist-utils) [![codecov](https://codecov.io/gh/cpp-playground/typelist-utils/branch/main/graph/badge.svg?token=ZDSZZLN6MP)](https://codecov.io/gh/cpp-playground/typelist-utils) diff --git a/include/typelist_utils/sort.hpp b/include/typelist_utils/sort.hpp index 4f40372..6abc870 100644 --- a/include/typelist_utils/sort.hpp +++ b/include/typelist_utils/sort.hpp @@ -42,10 +42,12 @@ template typename Predicate> requires tl::concepts::binary_value_predicate -struct merge, std::tuple, Predicate> +class merge, std::tuple, Predicate> { using list_a = std::tuple; using list_b = std::tuple; + + public: using type = std::conditional_t< Predicate::value, tl::concat_t, typename merge, list_b, Predicate>::type>, @@ -60,6 +62,11 @@ using merge_t = typename merge::type; } // namespace sort_impl +/** + * @brief Sorts a tuple-like type using the given predicate. + * @tparam T The tuple-like type. + * @tparam Predicate The binary value predicate to use for sorting. + */ template typename Predicate> struct sort; @@ -77,12 +84,13 @@ struct sort, Predicate> // Inductive step template typename Predicate> -struct sort, Predicate> +class sort, Predicate> { using input_t = std::tuple; using left_sort_t = typename sort, Predicate>::type; using right_sort_t = typename sort, Predicate>::type; + public: using type = tl::sort_impl::merge_t; }; diff --git a/include/typelist_utils/traits.hpp b/include/typelist_utils/traits.hpp index 353b7ab..919a3da 100644 --- a/include/typelist_utils/traits.hpp +++ b/include/typelist_utils/traits.hpp @@ -3,11 +3,28 @@ #include #include +/** + * @brief Namespace containing trait types + */ namespace tl::traits { + +/** + * @brief Trait type used to check if a given type is a tuple + * Inherits std::true_type if so, std::false_type otherwise. + * + * @tparam T Type to check + */ template struct is_tuple : std::false_type {}; + +/** + * @brief Trait type used to check if a given type is a tuple + * Inherits std::true_type if so, std::false_type otherwise. + * + * @tparam T Type to check + */ template struct is_tuple> : std::true_type {}; @@ -17,40 +34,102 @@ constexpr auto is_tuple_v = is_tuple::value; } // namespace tl::traits +/** + * @brief Namespace containing concepts + */ namespace tl::concepts { + +/** + * @brief Concept checking that 2 given types are the same + * @tparam T First type to check + * @tparam U Second type to check + */ template concept same_as = std::is_same_v; +/** + * @brief Concept checking a given type is a tuple type + * @tparam T Type to check + */ template concept tuple = tl::traits::is_tuple_v; +/** + * @brief Concept checking that a given type can be used as a binary value predicate for + * 2 other types. + * + * A binary value predicate is a type that, given 2 types exposes a static field + * value of type bool + * + * @tparam P Predicate type to check + * @tparam T First type for the predicate to be used on + * @tparam U Second type for the predicate to be used on + */ template