.. _program_listing_file_include_concepts.hpp: Program Listing for File concepts.hpp ===================================== |exhale_lsh| :ref:`Return to documentation for file ` (``include/concepts.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "htlist.hpp" #include #include #include #include #include #include #include namespace ctql { template concept is_bits_array = std::is_trivially_copyable_v && std::is_trivially_copyable_v; template concept is_complex = requires(T t) { typename T::value_type; std::is_same_v>; }; template concept is_vector = requires(T t) { typename T::value_type; std::is_same_v>; }; template concept is_map = requires(T t) { typename T::key_type; typename T::mapped_type; std::is_same_v> or std::is_same_v> or std::is_same_v>; }; template concept is_set = requires(T t) { typename T::value_type; std::is_same_v>; }; template concept is_pair = requires(T) { std::is_same_v>; }; namespace detail { template constexpr bool is_tuple_aux(std::index_sequence) { return std::is_same_v...>>; } } // namespace detail template struct is_std_array : std::false_type { }; template struct is_std_array> : std::true_type { }; template concept is_array = requires(T t) { typename T::value_type; std::is_same_v::value>>; }; template concept is_tuple = detail::is_tuple_aux(std::make_index_sequence::value>()); template struct is_same_or_const { static constexpr bool value = false; }; template struct is_same_or_const { static constexpr bool value = true; }; template struct is_same_or_const { static constexpr bool value = true; }; template concept is_same = std::is_same_v; #define $type_eq(T1, T2) std::is_same_v template concept is_not_same = not is_same; template concept is_conv_to = std::is_convertible_v; template concept is_not_conv_to = not is_conv_to; template concept is = std::conditional_t, std::is_void, is_same_or_const>::value; template concept is_not = not is; template struct function_traits; template struct function_traits { // as C literal function using as_c_function = Return_t(Args_t...); // as std::function using as_std_function = std::function; // return type using return_t = typename as_std_function::result_type; // number of arguments static constexpr uint64_t n_args = sizeof...(Args_t); // all argument types as tuple type using argument_ts = std::tuple; // type of i-th argument template using argument_type = std::tuple_element_t; }; template using get_nth_argument_t = std::tuple_element_t::argument_ts>; namespace detail { template struct as_c_function; template struct as_c_function { using value = Return_t(Args_t...); }; template struct as_c_function> { using value = Return_t(Args_t...); }; template using as_c_function_v = typename as_c_function::value; } // namespace detail template concept is_function_with_signature = std::is_invocable_v, Args_t...> and std::conditional_t< std::is_void_v, std::is_void>::return_t>, std::is_same< typename function_traits>::return_t, Return_t>>::value; // ---------- extraction helpers ---------- template struct to_variant; template struct to_variant> { using type = std::variant; }; template struct to_tuple; template struct to_tuple> { using type = std::tuple; }; }