From 3912f376122d97101c42f29a3948cf4ee06eec8a Mon Sep 17 00:00:00 2001 From: badair Date: Mon, 28 Mar 2016 04:00:04 -0500 Subject: [PATCH] code cleanup minutia --- include/callable_traits/any_arg.hpp | 2 + include/callable_traits/arity.hpp | 65 ++++++- include/callable_traits/best_match.hpp | 5 +- include/callable_traits/bind_expression.hpp | 56 +----- .../bind_expression_parser.hpp | 5 +- include/callable_traits/callable_traits.hpp | 24 ++- include/callable_traits/can_dereference.hpp | 36 ---- include/callable_traits/can_invoke_t.hpp | 85 --------- .../callable_traits/categorize_bind_arg.hpp | 20 +-- include/callable_traits/constraints.hpp | 59 ------- include/callable_traits/default_dispatch.hpp | 20 --- .../dereferenceable_object.hpp | 37 ---- include/callable_traits/flag_map.hpp | 42 ----- include/callable_traits/flags.hpp | 164 ------------------ include/callable_traits/function.hpp | 15 +- include/callable_traits/function_object.hpp | 31 +++- include/callable_traits/general.hpp | 39 ----- include/callable_traits/generalize.hpp | 49 ++++++ include/callable_traits/generalized_class.hpp | 70 ++++++++ .../has_normal_call_operator.hpp | 37 ---- .../callable_traits/is_bind_expression.hpp | 31 ---- .../callable_traits/is_reference_wrapper.hpp | 37 ++++ .../member_pointer_utilities.hpp | 21 +-- .../callable_traits/normalize_reference.hpp | 87 ---------- include/callable_traits/ph.hpp | 41 ----- ...placeholder_routes.hpp => placeholder.hpp} | 44 ++++- include/callable_traits/pmd.hpp | 26 --- include/callable_traits/pmf.hpp | 12 +- include/callable_traits/qualifier_traits.hpp | 40 ----- include/callable_traits/qualifiers.hpp | 133 ++++++++++++++ .../remove_duplicate_placeholders.hpp | 53 ------ .../remove_reference_if_ptr.hpp | 28 --- .../set_function_qualifiers.hpp | 3 +- include/callable_traits/tags.hpp | 7 - include/callable_traits/test_invoke.hpp | 15 +- include/callable_traits/traits.hpp | 16 +- include/callable_traits/tuple_group_by.hpp | 4 +- .../{sort_tuple.hpp => tuple_sort.hpp} | 2 +- include/callable_traits/unwrap_reference.hpp | 35 ++++ 39 files changed, 515 insertions(+), 981 deletions(-) delete mode 100644 include/callable_traits/can_invoke_t.hpp delete mode 100644 include/callable_traits/constraints.hpp delete mode 100644 include/callable_traits/default_dispatch.hpp delete mode 100644 include/callable_traits/dereferenceable_object.hpp delete mode 100644 include/callable_traits/flag_map.hpp delete mode 100644 include/callable_traits/flags.hpp delete mode 100644 include/callable_traits/general.hpp create mode 100644 include/callable_traits/generalize.hpp create mode 100644 include/callable_traits/generalized_class.hpp delete mode 100644 include/callable_traits/has_normal_call_operator.hpp delete mode 100644 include/callable_traits/is_bind_expression.hpp create mode 100644 include/callable_traits/is_reference_wrapper.hpp delete mode 100644 include/callable_traits/normalize_reference.hpp delete mode 100644 include/callable_traits/ph.hpp rename include/callable_traits/{placeholder_routes.hpp => placeholder.hpp} (76%) delete mode 100644 include/callable_traits/qualifier_traits.hpp create mode 100644 include/callable_traits/qualifiers.hpp delete mode 100644 include/callable_traits/remove_duplicate_placeholders.hpp delete mode 100644 include/callable_traits/remove_reference_if_ptr.hpp rename include/callable_traits/{sort_tuple.hpp => tuple_sort.hpp} (98%) create mode 100644 include/callable_traits/unwrap_reference.hpp diff --git a/include/callable_traits/any_arg.hpp b/include/callable_traits/any_arg.hpp index 625245a..86b0353 100644 --- a/include/callable_traits/any_arg.hpp +++ b/include/callable_traits/any_arg.hpp @@ -27,9 +27,11 @@ namespace callable_traits { any_arg() = default; #if !defined(_MSC_VER) + //MSVC doesn't like this because it can deduce 'void' template any_arg(T&&...); #endif //!defined(_MSC_VER) + }; } } diff --git a/include/callable_traits/arity.hpp b/include/callable_traits/arity.hpp index 41794bb..bafd101 100644 --- a/include/callable_traits/arity.hpp +++ b/include/callable_traits/arity.hpp @@ -10,8 +10,9 @@ Distributed under the Boost Software License, Version 1.0. #ifndef CALLABLE_TRAITS_ARITY_HPP #define CALLABLE_TRAITS_ARITY_HPP +#include +#include #include -#include #include #include @@ -19,6 +20,68 @@ namespace callable_traits { namespace detail { + template + struct can_invoke_t { + + using callable = typename Dispatch::type; + using class_type = typename Dispatch::class_type; + using is_member_pointer = typename Dispatch::is_member_pointer; + + using invoker = typename std::conditional< + is_member_pointer::value, + test_invoke, + test_invoke + >::type; + + using test = typename std::conditional< + is_member_pointer::value, + decltype(invoker{}( + std::declval(), + std::declval(), + std::declval()... + )), + decltype(invoker{}( + std::declval(), + std::declval()... + )) + >::type; + + static constexpr bool value = + !std::is_same{}; + + static constexpr int arg_count = invoker::arg_count; + }; + + template + struct can_invoke_t { + + using callable = typename Dispatch::type; + using class_type = typename Dispatch::class_type; + using is_member_pointer = typename Dispatch::is_member_pointer; + + using invoker = typename std::conditional< + is_member_pointer::value, + test_invoke, + test_invoke + >::type; + + using invoke_type = typename Dispatch::invoke_type; + + using test = typename std::conditional< + is_member_pointer::value, + decltype(invoker{}( + std::declval(), + std::declval() + )), + decltype(invoker{}(std::declval())) + >::type; + + static constexpr bool value = + !std::is_same::value; + + static constexpr int arg_count = 0; + }; + template struct max_args { static constexpr bool value = true; diff --git a/include/callable_traits/best_match.hpp b/include/callable_traits/best_match.hpp index 26b079d..e9689b8 100644 --- a/include/callable_traits/best_match.hpp +++ b/include/callable_traits/best_match.hpp @@ -8,7 +8,8 @@ Distributed under the Boost Software License, Version 1.0. #ifndef CALLABLE_TRAITS_BEST_MATCH_HPP #define CALLABLE_TRAITS_BEST_MATCH_HPP -#include +#include +#include #include #include @@ -107,7 +108,7 @@ namespace callable_traits { }; template - using sorted_cartesian_product_of_conversions = sort_tuple< + using sorted_cartesian_product_of_conversions = tuple_sort< std::tuple...>, conversion_result_sort_predicate >; diff --git a/include/callable_traits/bind_expression.hpp b/include/callable_traits/bind_expression.hpp index 8842f81..a1f3057 100644 --- a/include/callable_traits/bind_expression.hpp +++ b/include/callable_traits/bind_expression.hpp @@ -14,10 +14,7 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include -#include -#include -#include -#include +#include #include #include //#include @@ -35,34 +32,6 @@ namespace callable_traits { PhRouteLeft::ph_value < PhRouteRight::ph_value; }; - template - struct placeholders_mapped_to_original_signature; - - template - struct placeholders_mapped_to_original_signature< - PhRoutesTuple, OriginalArgsTuple, std::index_sequence> { - - //this is where the magic happens - using type = std::tuple< - typename std::tuple_element< - std::tuple_element::type::original_arg_index, - OriginalArgsTuple - >::type... - >; - }; - - template - struct placeholders_mapped_to_original_signature< - PhRoutesTuple, std::tuple<>, std::index_sequence> { - using type = std::tuple<>; - }; - - template - struct placeholders_mapped_to_original_signature< - T, std::tuple, std::index_sequence> { - using type = std::tuple; - }; - template struct bind_expressions_filter; template <> struct bind_expressions_filter<> { using type = std::tuple<>; }; @@ -152,10 +121,6 @@ namespace callable_traits { using inner_bind_expressions = typename remove_non_bind_expressions::type; - using has_inner_bind_expressions = std::is_same< - inner_bind_expressions, std::tuple<> - >; - using flattened_bind_expressions = typename flatten_bind_expressions::type; @@ -164,26 +129,7 @@ namespace callable_traits { bind_args_tuple >::type; - using sorted_placeholder_routes = - typename remove_duplicate_placeholders< - sort_tuple< - placeholder_route_map, - compare_ph_value - > - >::type; - - using placeholder_count = std::tuple_size< - sorted_placeholder_routes - >; - using original_args = typename traits::arg_types; - - /*using arg_types = typename placeholders_mapped_to_original_signature< - sorted_placeholder_routes, - original_args, - std::make_index_sequence - >::type;*/ - using return_type = typename traits::return_type; }; diff --git a/include/callable_traits/bind_expression_parser.hpp b/include/callable_traits/bind_expression_parser.hpp index 4391c0e..36734ad 100644 --- a/include/callable_traits/bind_expression_parser.hpp +++ b/include/callable_traits/bind_expression_parser.hpp @@ -10,10 +10,11 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include +#include #include #include #include +#include #include #include @@ -33,7 +34,7 @@ namespace callable_traits { typename BindExprs::bind_args_tuple >::type>()...)); - using type = sort_tuple< + using type = tuple_sort< placeholder_route_map, compare_ph_value >; diff --git a/include/callable_traits/callable_traits.hpp b/include/callable_traits/callable_traits.hpp index ad2aeb7..cd8d434 100644 --- a/include/callable_traits/callable_traits.hpp +++ b/include/callable_traits/callable_traits.hpp @@ -22,30 +22,38 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include -#include -#include -#include -#include #include #include #include #include -#include #include - -//todo remove? -#include +#include #include #include namespace callable_traits { + namespace detail { + + template + struct value_type_pair { + using type = T; + static constexpr const bool value = Value; + }; + } + namespace no_sfinae { template using args = typename detail::traits::arg_types; + template + using arg_at = typename detail::disjunction< + detail::value_type_pair>::value <= I, invalid_type>, + detail::value_type_pair>::type> + >::type; + template using signature = typename detail::traits::function_type; diff --git a/include/callable_traits/can_dereference.hpp b/include/callable_traits/can_dereference.hpp index 0d1b8f5..674c327 100644 --- a/include/callable_traits/can_dereference.hpp +++ b/include/callable_traits/can_dereference.hpp @@ -39,42 +39,6 @@ namespace callable_traits { using can_dereference = std::integral_constant::value >; - - template - struct dereference_if_not_function { - using type = T; - }; - - template - struct is_class_after_dereference - { - template - struct check {}; - - template::value>::value, U>::type> - static typename std::enable_if< - std::is_class< - typename std::remove_reference())>::type - >::value, - std::int8_t - >::type test(std::nullptr_t); - - template - static std::int16_t test(...); - - static constexpr const bool value = - sizeof(test(nullptr)) == sizeof(std::int8_t); - }; - - template - using can_dereference_to_class = std::integral_constant::value - >; - - template - using cannot_dereference_to_class = std::integral_constant::value - >; } } diff --git a/include/callable_traits/can_invoke_t.hpp b/include/callable_traits/can_invoke_t.hpp deleted file mode 100644 index 5c1ce85..0000000 --- a/include/callable_traits/can_invoke_t.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_CAN_INVOKE_T_HPP -#define CALLABLE_TRAITS_CAN_INVOKE_T_HPP - -#include -#include -#include - -namespace callable_traits { - - namespace detail { - - template - struct can_invoke_t { - - using callable = typename Dispatch::type; - using class_type = typename Dispatch::class_type; - using is_member_pointer = typename Dispatch::is_member_pointer; - - using invoker = typename std::conditional< - is_member_pointer::value, - test_invoke, - test_invoke - >::type; - - using test = typename std::conditional< - is_member_pointer::value, - decltype(invoker{}( - std::declval(), - std::declval(), - std::declval()... - )), - decltype(invoker{}( - std::declval(), - std::declval()... - )) - >::type; - - static constexpr bool value = - !std::is_same{}; - - static constexpr int arg_count = invoker::arg_count; - }; - - template - struct can_invoke_t { - - using callable = typename Dispatch::type; - using class_type = typename Dispatch::class_type; - using is_member_pointer = typename Dispatch::is_member_pointer; - - using invoker = typename std::conditional< - is_member_pointer::value, - test_invoke, - test_invoke - >::type; - - using invoke_type = typename Dispatch::invoke_type; - - using test = typename std::conditional< - is_member_pointer::value, - decltype(invoker{}( - std::declval(), - std::declval() - )), - decltype(invoker{}(std::declval())) - >::type; - - static constexpr bool value = - !std::is_same::value; - - static constexpr int arg_count = 0; - }; - } -} - -#endif diff --git a/include/callable_traits/categorize_bind_arg.hpp b/include/callable_traits/categorize_bind_arg.hpp index 620c798..d47ba67 100644 --- a/include/callable_traits/categorize_bind_arg.hpp +++ b/include/callable_traits/categorize_bind_arg.hpp @@ -8,7 +8,7 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ -#include +#include #include #include #include @@ -26,32 +26,23 @@ namespace callable_traits { using type = typename std::conditional< std::is_placeholder< T >::value == 0, bind_value, - ph::value> + placeholder::value> >::type; - - using bind_expr = invalid_type; - using is_bind_expression = std::false_type; }; template struct categorize_bind_arg< bind_value > { using type = detail::bind_value; - using bind_expr = invalid_type; - using is_bind_expression = std::false_type; }; template struct categorize_bind_arg< std::reference_wrapper > { using type = std::reference_wrapper; - using bind_expr = invalid_type; - using is_bind_expression = std::false_type; }; template - struct categorize_bind_arg< ph > { - using type = ph; - using bind_expr = invalid_type; - using is_bind_expression = std::false_type; + struct categorize_bind_arg< placeholder > { + using type = placeholder; }; template @@ -64,9 +55,6 @@ namespace callable_traits { any_arg<>, return_type >::type; - - using bind_expr = bind_expression; - using is_bind_expression = std::true_type; }; } } diff --git a/include/callable_traits/constraints.hpp b/include/callable_traits/constraints.hpp deleted file mode 100644 index 116d828..0000000 --- a/include/callable_traits/constraints.hpp +++ /dev/null @@ -1,59 +0,0 @@ - /*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_CONSTRAINTS_HPP -#define CALLABLE_TRAITS_CONSTRAINTS_HPP - -#include -#include -#include - -// CALLABLE_TRAITS_REQUIRES_ and CALLABLE_TRAITS_REQUIRES adapted from Range-v3 here: -// https://github.com/ericniebler/range-v3/blob/6600e6054513202e61a067de48c4a05ca2b11099/include/range/v3/utility/concepts.hpp#L861 -// Copyright Eric Niebler 2013-2014 - -#define CALLABLE_TRAITS_PP_CAT_(X, Y) X ## Y -#define CALLABLE_TRAITS_PP_CAT(X, Y) CALLABLE_TRAITS_PP_CAT_(X, Y) - -#define CALLABLE_TRAITS_REQUIRES_(...) \ - int CALLABLE_TRAITS_PP_CAT(callable_traits_requires_, __LINE__) = 42, \ - typename std::enable_if< \ - (CALLABLE_TRAITS_PP_CAT(callable_traits_requires_, __LINE__) == 43) || (__VA_ARGS__), \ - bool \ - >::type constraint_success = true \ -/**/ - -#define CALLABLE_TRAITS_REQUIRES(...) \ - template< \ - int CALLABLE_TRAITS_PP_CAT(callable_traits_requires_, __LINE__) = 42, \ - typename std::enable_if< \ - (CALLABLE_TRAITS_PP_CAT(callable_traits_requires_, __LINE__) == 43) || (__VA_ARGS__),\ - bool \ - >::type constraint_success = true> \ -/**/ - -namespace callable_traits { - - namespace detail { - - struct callable_dummy { - void operator()() {} - }; - - template - using default_normal_callable = typename std::conditional< - has_normal_call_operator::value, - T, - callable_dummy - >::type; - - } -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/default_dispatch.hpp b/include/callable_traits/default_dispatch.hpp deleted file mode 100644 index 76b263d..0000000 --- a/include/callable_traits/default_dispatch.hpp +++ /dev/null @@ -1,20 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_DEFAULT_DISPATCH_HPP -#define CALLABLE_TRAITS_DEFAULT_DISPATCH_HPP - -template -struct default_dispatch { - static constexpr const bool is_valid = true; - static constexpr const bool value = is_valid; - using traits = T; -}; - -#endif \ No newline at end of file diff --git a/include/callable_traits/dereferenceable_object.hpp b/include/callable_traits/dereferenceable_object.hpp deleted file mode 100644 index db89ae1..0000000 --- a/include/callable_traits/dereferenceable_object.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_DEREFERENCEABLE_OBJECT_HPP -#define CALLABLE_TRAITS_DEREFERENCEABLE_OBJECT_HPP - -namespace clbl { - - template - using default_dereferenceable = typename std::conditional< - can_dereference::value, - T, - int* - >::type; - - template< - typename Ptr, - typename std::enable_if< - can_dereference::value - && std::is_class< - typename std::remove_reference< - decltype(*std::declval>()) - >::type - >::value, - int* - >::type = nullptr - > - using dereferenceable_object = Ptr; -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/flag_map.hpp b/include/callable_traits/flag_map.hpp deleted file mode 100644 index cb39fd9..0000000 --- a/include/callable_traits/flag_map.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_FLAG_MAP_HPP -#define CALLABLE_TRAITS_FLAG_MAP_HPP - -#include - -namespace callable_traits { - - namespace detail { - - template - struct flag_map { - static_assert(sizeof(T) < 0, - "Invalid argument passed to flag_map template."); - - static constexpr flags value = default_; - }; - - template<> struct flag_map { static constexpr flags value = default_; }; - template<> struct flag_map { static constexpr flags value = lref_; }; - template<> struct flag_map { static constexpr flags value = rref_; }; - template<> struct flag_map { static constexpr flags value = const_; }; - template<> struct flag_map { static constexpr flags value = const_ | lref_; }; - template<> struct flag_map { static constexpr flags value = const_ | rref_; }; - template<> struct flag_map { static constexpr flags value = volatile_; }; - template<> struct flag_map { static constexpr flags value = volatile_ | lref_; }; - template<> struct flag_map { static constexpr flags value = volatile_ | rref_; }; - template<> struct flag_map { static constexpr flags value = const_ | volatile_; }; - template<> struct flag_map { static constexpr flags value = const_ | volatile_ | lref_; }; - template<> struct flag_map { static constexpr flags value = const_ | volatile_ | rref_; }; - } -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/flags.hpp b/include/callable_traits/flags.hpp deleted file mode 100644 index edb50ef..0000000 --- a/include/callable_traits/flags.hpp +++ /dev/null @@ -1,164 +0,0 @@ -/*! -@file -Defines `flags` - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_FLAGS_HPP -#define CALLABLE_TRAITS_FLAGS_HPP - -namespace callable_traits { - - namespace detail { - - //! flags are bit flags used to signify cv-qualifiers - //! and ref-qualifiers/reference types - using flags = std::uint32_t; - - /* - This grid is useful for debugging type errors where - the error messages often include a `flags` value: - - value | RR LR V C | result - -------------------------------------------- - 0 | 0 0 0 0 | default - 1 | 0 0 0 1 | const - 2 | 0 0 1 0 | volatile - 3 | 0 0 1 1 | const volatile - -------------------------------------------- - 4 | 0 1 0 0 | lref - 5 | 0 1 0 1 | const lref - 6 | 0 1 1 0 | volatile lref - 7 | 0 1 1 1 | const volatile lref - -------------------------------------------- - 8 | 1 0 0 0 | rref - 9 | 1 0 0 1 | const rref - 10 | 1 0 1 0 | volatile rref - 11 | 1 0 1 1 | const volatile rref - -------------------------------------------- - 12+ | 1 1 * * | invalid - use `collapse` - - */ - - constexpr flags max_flags_value = 11; - - //! Flag representing the default qualifiers on a type - //! or member function overload. - constexpr flags default_ = 0; - - //! Flag representing a const qualifier on a type or - //! member function overload. - constexpr flags const_ = 1; - - //! Flag representing a volatile qualifier on a type - //! or member function overload. - constexpr flags volatile_ = 2; - - //! Flag representing an lvalue reference type, or - //! an lvalue-reference-qualified member function - //! overload. - constexpr flags lvalue_reference_ = 4; - - //! shorthand for `lvalue_reference_`. - constexpr flags lref_ = 4; - - //! shorthand for `const_ | lvalue_reference_`. - constexpr flags clref_ = 5; - - //! Flag representing an lvalue reference type, or - //! an rvalue-reference-qualified member function - //! overload. - constexpr flags rvalue_reference_ = 8; - - //! shorthand for `rvalue_reference_`. - constexpr flags rref_ = 8; - - constexpr flags cv_ = 3; - - template - using add_const = std::integral_constant; - - template - using remove_const = std::integral_constant; - - template - using is_const = std::integral_constant; - - template - using add_volatile = std::integral_constant; - - template - using remove_volatile = std::integral_constant; - - template - using is_volatile = std::integral_constant; - - template - using add_cv = std::integral_constant; - - template - using remove_cv = std::integral_constant; - - template - using remove_reference = std::integral_constant; - - template - using is_lvalue_reference = std::integral_constant; - - //is_rvalue_reference uses reference collapsing rules - template - using is_rvalue_reference = std::integral_constant; - - template - using force_lvalue_reference = std::integral_constant; - - template - using force_rvalue_reference = std::integral_constant; - - template - using collapse = std::integral_constant; - - template - using add_lvalue_reference = std::integral_constant; - - template - using add_rvalue_reference = collapse; - - template - using guarantee_reference = std::integral_constant; - - template::type> - using cv_of = std::integral_constant::value ? const_ : default_) - | (std::is_volatile::value ? volatile_ : default_) - >; - - using force_ref = std::true_type; - - template - using ref_of = std::integral_constant::value ? rref_ - : (std::is_lvalue_reference::value ? lref_ - : (ForceRef::value ? lref_ : default_)) - >; - } -} -#endif \ No newline at end of file diff --git a/include/callable_traits/function.hpp b/include/callable_traits/function.hpp index f9322ee..386eaa0 100644 --- a/include/callable_traits/function.hpp +++ b/include/callable_traits/function.hpp @@ -11,13 +11,11 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_FUNCTION_HPP #include -#include -#include #include -#include +#include #include #include -#include +#include #include @@ -41,7 +39,6 @@ public: using is_function_general = std::true_type; \ \ using traits = function; \ - using callable_traits_tag = function_tag; \ using return_type = Return; \ using arg_types = std::tuple; \ using type = Return(Args...) QUAL; \ @@ -102,7 +99,6 @@ public: using is_function = std::true_type; \ using is_function_general = std::true_type; \ using traits = function; \ - using callable_traits_tag = function_tag; \ using return_type = Return; \ using arg_types = std::tuple; \ using type = Return (Args..., ...) QUAL; \ @@ -149,7 +145,7 @@ namespace callable_traits { namespace detail { template - struct function : function_object> { + struct function : function_object> { static constexpr const bool value = false; using traits = function; }; @@ -167,11 +163,6 @@ namespace callable_traits { CALLABLE_TRAITS_SPECIALIZE_FUNCTION(volatile &&); CALLABLE_TRAITS_SPECIALIZE_FUNCTION(const volatile &&); - template - struct function > { - using traits = function; - }; - template struct function : function { using traits = function; diff --git a/include/callable_traits/function_object.hpp b/include/callable_traits/function_object.hpp index 7a2ca39..e08bdb7 100644 --- a/include/callable_traits/function_object.hpp +++ b/include/callable_traits/function_object.hpp @@ -10,9 +10,8 @@ Distributed under the Boost Software License, Version 1.0. #ifndef CALLABLE_TRAITS_FUNCTION_OBJECT_HPP #define CALLABLE_TRAITS_FUNCTION_OBJECT_HPP -#include +#include #include -#include #include #include @@ -21,6 +20,32 @@ namespace callable_traits { namespace detail { + template + struct has_normal_call_operator + { + template struct check { check(std::nullptr_t) {} }; + + template + static std::int8_t test(check); + + template + static std::int16_t test(...); + + static constexpr bool value = sizeof(test(nullptr)) == sizeof(std::int8_t); + + }; + + struct callable_dummy { + void operator()() {} + }; + + template + using default_normal_callable = typename std::conditional< + has_normal_call_operator::value, + T, + callable_dummy + >::type; + template struct ambiguous_function_object { using arg_types = std::tuple; @@ -79,7 +104,7 @@ namespace callable_traits { }; template - struct function_object > { + struct function_object > { static constexpr const bool value = false; using traits = function_object; }; diff --git a/include/callable_traits/general.hpp b/include/callable_traits/general.hpp deleted file mode 100644 index 6c601be..0000000 --- a/include/callable_traits/general.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_GENERAL_HPP -#define CALLABLE_TRAITS_GENERAL_HPP - -#include -#include -#include - - -namespace callable_traits { - - namespace detail { - - template - struct general; - - template - struct general::type>> { - using type = typename std::remove_reference::type; - using original_type = T; - }; - - template - struct general::type>> { - using type = typename std::remove_reference())>::type; - using original_type = T; - }; - } -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/generalize.hpp b/include/callable_traits/generalize.hpp new file mode 100644 index 0000000..66b8c13 --- /dev/null +++ b/include/callable_traits/generalize.hpp @@ -0,0 +1,49 @@ +/*! +@file + +@copyright Barrett Adair 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +*/ + +#ifndef CALLABLE_TRAITS_GENERALIZE_HPP +#define CALLABLE_TRAITS_GENERALIZE_HPP + +#include +#include +#include + +namespace callable_traits { + + namespace detail { + + template + struct generalize_t { + using type = T; + }; + + template + struct generalize_t::value && !is_reference_wrapper::value + >>{ + using type = decltype(*std::declval()); + }; + + template + struct generalize_t> { + using type = decltype(std::declval().get()); + }; + + // generalize expects a pointer, a reference, or a reference_wrapper. + // When T is a pointer, generalize is the resulting type + // of the pointer dereferenced. When T is an std::reference_wrapper, + // generalize is the underlying reference type. Otherwise, generalize + // is T. + + template + using generalize = typename generalize_t::type; + } +} + +#endif diff --git a/include/callable_traits/generalized_class.hpp b/include/callable_traits/generalized_class.hpp new file mode 100644 index 0000000..9bd1adc --- /dev/null +++ b/include/callable_traits/generalized_class.hpp @@ -0,0 +1,70 @@ +/*! +@file + +@copyright Barrett Adair 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +*/ + +#ifndef CALLABLE_TRAITS_GENERALIZED_CLASS_HPP +#define CALLABLE_TRAITS_GENERALIZED_CLASS_HPP + +#include +#include +#include + + +namespace callable_traits { + + namespace detail { + + template + struct is_class_after_dereference + { + template + struct check {}; + + template::value>::value, U>::type> + static typename std::enable_if< + std::is_class< + typename std::remove_reference())>::type + >::value, + std::int8_t + >::type test(std::nullptr_t); + + template + static std::int16_t test(...); + + static constexpr const bool value = + sizeof(test(nullptr)) == sizeof(std::int8_t); + }; + + template + using can_dereference_to_class = std::integral_constant::value + >; + + template + using cannot_dereference_to_class = std::integral_constant::value + >; + + template + struct generalized_class; + + template + struct generalized_class::type>> { + using type = typename std::remove_reference::type; + using original_type = T; + }; + + template + struct generalized_class::type>> { + using type = typename std::remove_reference())>::type; + using original_type = T; + }; + } +} + +#endif \ No newline at end of file diff --git a/include/callable_traits/has_normal_call_operator.hpp b/include/callable_traits/has_normal_call_operator.hpp deleted file mode 100644 index acc9fe3..0000000 --- a/include/callable_traits/has_normal_call_operator.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_HAS_NORMAL_CALL_OPERATOR_HPP -#define CALLABLE_TRAITS_HAS_NORMAL_CALL_OPERATOR_HPP - -#include -#include - -namespace callable_traits { - - namespace detail { - - template - struct has_normal_call_operator - { - template struct check { check(std::nullptr_t) {} }; - - template - static std::int8_t test(check); - - template - static std::int16_t test(...); - - static constexpr bool value = sizeof(test(nullptr)) == sizeof(std::int8_t); - - }; - } -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/is_bind_expression.hpp b/include/callable_traits/is_bind_expression.hpp deleted file mode 100644 index f133ead..0000000 --- a/include/callable_traits/is_bind_expression.hpp +++ /dev/null @@ -1,31 +0,0 @@ - /*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_IS_BIND_EXPRESSION_HPP -#define CALLABLE_TRAITS_IS_BIND_EXPRESSION_HPP - -#include - -namespace callable_traits { - - namespace detail { - - template - struct is_bind_expression { - static constexpr const bool value = false; - }; - - template - struct is_bind_expression> { - static constexpr const bool value = true; - }; - } -} - -#endif diff --git a/include/callable_traits/is_reference_wrapper.hpp b/include/callable_traits/is_reference_wrapper.hpp new file mode 100644 index 0000000..bbbb63f --- /dev/null +++ b/include/callable_traits/is_reference_wrapper.hpp @@ -0,0 +1,37 @@ +/*! +@file + +@copyright Barrett Adair 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +*/ + +#ifndef CALLABLE_TRAITS_IS_REFERENCE_WRAPPER_HPP +#define CALLABLE_TRAITS_IS_REFERENCE_WRAPPER_HPP + +#include +#include +#include + + +namespace callable_traits { + + namespace detail { + + template + struct is_reference_wrapper_t { + using type = std::false_type; + }; + + template + struct is_reference_wrapper_t> { + using type = std::true_type; + }; + + template + using is_reference_wrapper = typename is_reference_wrapper_t>::type; + } +} + +#endif \ No newline at end of file diff --git a/include/callable_traits/member_pointer_utilities.hpp b/include/callable_traits/member_pointer_utilities.hpp index 4a76187..f09cda4 100644 --- a/include/callable_traits/member_pointer_utilities.hpp +++ b/include/callable_traits/member_pointer_utilities.hpp @@ -19,22 +19,19 @@ namespace callable_traits { template using add_member_pointer = T Class::*; - namespace mpdetail { + template + struct remove_member_pointer_t { + using type = T; + }; - template - struct remove_member_pointer_t { - using type = T; - }; - - template - struct remove_member_pointer_t{ - using type = T; - }; - } + template + struct remove_member_pointer_t{ + using type = T; + }; template using remove_member_pointer = - typename mpdetail::remove_member_pointer_t::type; + typename remove_member_pointer_t::type; } } diff --git a/include/callable_traits/normalize_reference.hpp b/include/callable_traits/normalize_reference.hpp deleted file mode 100644 index d400d8d..0000000 --- a/include/callable_traits/normalize_reference.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_NORMALIZE_REFERENCE_HPP -#define CALLABLE_TRAITS_NORMALIZE_REFERENCE_HPP - -#include -#include -#include -#include - -namespace callable_traits { - - namespace detail { - - template - struct is_reference_wrapper_t { - using type = std::false_type; - }; - - template - struct is_reference_wrapper_t> { - using type = std::true_type; - }; - - template - using is_reference_wrapper = typename is_reference_wrapper_t>::type; - - template - struct normalize_reference_t { - using type = T; - }; - - template - struct normalize_reference_t::value && !is_reference_wrapper::value - >>{ - using type = T; - }; - - template - struct normalize_reference_t> { - using type = decltype(std::declval().get()); - }; - - // normalize_reference expects a pointer, a reference, or a reference_wrapper. - // When T is a pointer, normalize_reference is the resulting type - // of the pointer dereferenced. When T is an std::reference_wrapper, - // normalize_reference is the underlying reference type. - - template - using normalize_reference = typename normalize_reference_t::type; - - template - struct normalize_ptr_or_reference_t { - using type = T; - }; - - template - struct normalize_ptr_or_reference_t::value && !is_reference_wrapper::value - >>{ - using type = decltype(*std::declval()); - }; - - template - struct normalize_ptr_or_reference_t> { - using type = decltype(std::declval().get()); - }; - - // normalize_reference expects a pointer, a reference, or a reference_wrapper. - // When T is a pointer, normalize_reference is the resulting type - // of the pointer dereferenced. When T is an std::reference_wrapper, - // normalize_reference is the underlying reference type. - - template - using normalize_ptr_or_reference = typename normalize_ptr_or_reference_t::type; - } -} - -#endif diff --git a/include/callable_traits/ph.hpp b/include/callable_traits/ph.hpp deleted file mode 100644 index 3d3a194..0000000 --- a/include/callable_traits/ph.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/*! -Copyright (c) 2002 Peter Dimov and Multi Media Ltd. -Copyright (c) 2016 Barrett Adair - -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ - -#ifndef CALLABLE_TRAITS_PH_HPP -#define CALLABLE_TRAITS_PH_HPP - -namespace callable_traits { - - template struct ph; - -} - -namespace std { - - template - struct is_placeholder< callable_traits::ph > - { - static constexpr const int value = I; - }; -} - -namespace callable_traits { - -template - struct ph { - - ph() = default; - - template - ph(T const &) { - static_assert(I == std::is_placeholder::value, "Invalid placeholder"); - } - }; -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/placeholder_routes.hpp b/include/callable_traits/placeholder.hpp similarity index 76% rename from include/callable_traits/placeholder_routes.hpp rename to include/callable_traits/placeholder.hpp index e650f7a..041e389 100644 --- a/include/callable_traits/placeholder_routes.hpp +++ b/include/callable_traits/placeholder.hpp @@ -1,18 +1,46 @@ /*! -@copyright Barrett Adair 2016 +Copyright (c) 2002 Peter Dimov and Multi Media Ltd. +Copyright (c) 2016 Barrett Adair Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ -#ifndef CALLABLE_TRAITS_BIND_PLACEHOLDER_ROUTES_HPP -#define CALLABLE_TRAITS_BIND_PLACEHOLDER_ROUTES_HPP +#ifndef CALLABLE_TRAITS_PLACEHOLDER_HPP +#define CALLABLE_TRAITS_PLACEHOLDER_HPP #include +#include +#include +#include -namespace callable_traits { +namespace callable_traits { - namespace detail { + namespace detail { + + template + struct placeholder { + + placeholder() = default; + + template + placeholder(T const &) { + static_assert(I == std::is_placeholder::value, "Invalid placeholder"); + } + }; + } +} +namespace std { + + template + struct is_placeholder< callable_traits::detail::placeholder > { + static constexpr const int value = I; + }; +} + +namespace callable_traits { + + namespace detail { template struct ph_route { @@ -81,10 +109,8 @@ namespace callable_traits { >::type >::type; - using type = sort_tuple; + using type = tuple_sort; }; - - } + } } - #endif \ No newline at end of file diff --git a/include/callable_traits/pmd.hpp b/include/callable_traits/pmd.hpp index 8cb02be..910a28c 100644 --- a/include/callable_traits/pmd.hpp +++ b/include/callable_traits/pmd.hpp @@ -12,11 +12,9 @@ Distributed under the Boost Software License, Version 1.0. #include -#include #include #include #include -#include #include namespace callable_traits { @@ -55,7 +53,6 @@ namespace callable_traits { using remove_member_pointer = D; -#ifdef _MSC_VER using remove_reference = invalid_type; using add_lvalue_reference = invalid_type; using add_rvalue_reference = invalid_type; @@ -68,29 +65,6 @@ namespace callable_traits { template using apply_return = invalid_type; -#else - using remove_reference = typename base::remove_reference T::*; - using add_lvalue_reference = typename base::add_lvalue_reference T::*; - using add_rvalue_reference = typename base::add_lvalue_reference T::*; - using add_const = typename base::add_const T::*; - using add_volatile = typename base::add_volatile T::*; - using add_cv = typename base::add_cv T::*; - using remove_const = typename base::remove_const T::*; - using remove_volatile = typename base::remove_volatile T::*; - using remove_cv = typename base::remove_cv T::*; - - template - using apply_return = detail::add_member_pointer< - msvc_workaround::apply_return_helper, - T - >; -#endif - - }; - - template - struct pmd > { - using traits = pmd; }; } } diff --git a/include/callable_traits/pmf.hpp b/include/callable_traits/pmf.hpp index e6d0f16..70f3ff6 100644 --- a/include/callable_traits/pmf.hpp +++ b/include/callable_traits/pmf.hpp @@ -11,11 +11,8 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_PMF_HPP #include -#include -#include -#include #include -#include +#include #include #define CALLABLE_TRAITS_SPECIALIZE_PMF(QUAL) \ @@ -38,7 +35,6 @@ public: using is_function_general = std::false_type; \ \ using traits = pmf; \ - using callable_traits_tag = pmf_tag; \ using return_type = Return; \ using arg_types = std::tuple; \ using type = Return(T::*)(Args...) QUAL; \ @@ -96,7 +92,6 @@ public: using is_function_general = std::false_type; \ \ using traits = pmf; \ - using callable_traits_tag = pmf_tag; \ using return_type = Return; \ using arg_types = std::tuple; \ using type = Return(CALLABLE_TRAITS_VARARGS_CC T::*)(Args..., ...) QUAL; \ @@ -165,11 +160,6 @@ namespace callable_traits { CALLABLE_TRAITS_SPECIALIZE_PMF(const &&); CALLABLE_TRAITS_SPECIALIZE_PMF(volatile &&); CALLABLE_TRAITS_SPECIALIZE_PMF(const volatile &&); - - template - struct pmf > { - using traits = pmf; - }; } } diff --git a/include/callable_traits/qualifier_traits.hpp b/include/callable_traits/qualifier_traits.hpp deleted file mode 100644 index d0f1707..0000000 --- a/include/callable_traits/qualifier_traits.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_QUALIFIER_TRAITS_HPP -#define CALLABLE_TRAITS_QUALIFIER_TRAITS_HPP - -#include - -namespace callable_traits { - - namespace detail { - - template - class qualifier_traits { - - protected: - - static constexpr flags cv_flags = cv_of::value; - static constexpr flags ref_flags = ref_of::value; - static constexpr flags q_flags = cv_flags | ref_flags; - - public: - - using is_reference_qualified = std::integral_constant; - using is_lvalue_reference_qualified = std::integral_constant; - using is_rvalue_reference_qualified = std::integral_constant; - using is_const_qualified = std::integral_constant; - using is_volatile_qualified = std::integral_constant; - using is_cv_qualified = std::integral_constant; - }; - } -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/qualifiers.hpp b/include/callable_traits/qualifiers.hpp new file mode 100644 index 0000000..17d8b7f --- /dev/null +++ b/include/callable_traits/qualifiers.hpp @@ -0,0 +1,133 @@ +/*! +@file +Defines `flags` + +@copyright Barrett Adair 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +*/ + +#ifndef CALLABLE_TRAITS_QUALIFIERS_HPP +#define CALLABLE_TRAITS_QUALIFIERS_HPP + +#include + +namespace callable_traits { + + namespace detail { + + //bit flags used to signify cv/ref qualifiers + using flags = std::uint32_t; + + /* + + | && & V C | + -------------------------------------------- + 0 | 0 0 0 0 | default + 1 | 0 0 0 1 | const + 2 | 0 0 1 0 | volatile + 3 | 0 0 1 1 | const volatile + -------------------------------------------- + 4 | 0 1 0 0 | & + 5 | 0 1 0 1 | const & + 6 | 0 1 1 0 | volatile & + 7 | 0 1 1 1 | const volatile & + -------------------------------------------- + 8 | 1 0 0 0 | && + 9 | 1 0 0 1 | const && + 10 | 1 0 1 0 | volatile && + 11 | 1 0 1 1 | const volatile && + + */ + + //! Flag representing the default qualifiers on a type + //! or member function overload. + constexpr flags default_ = 0; + + //! Flag representing a const qualifier on a type or + //! member function overload. + constexpr flags const_ = 1; + + //! Flag representing a volatile qualifier on a type + //! or member function overload. + constexpr flags volatile_ = 2; + + //! Flag representing an lvalue reference type, or + //! an lvalue-reference-qualified member function + //! overload. + constexpr flags lref_ = 4; + + //! Flag representing an lvalue reference type, or + //! an rvalue-reference-qualified member function + //! overload. + constexpr flags rref_ = 8; + + constexpr flags cv_ = 3; + + template + using remove_const = std::integral_constant; + + template + using is_const = std::integral_constant; + + template + using remove_volatile = std::integral_constant; + + template::type> + using cv_of = std::integral_constant::value ? const_ : default_) + | (std::is_volatile::value ? volatile_ : default_) + >; + + template + using ref_of = std::integral_constant::value ? rref_ + : (std::is_lvalue_reference::value ? lref_ + : (ForceRef::value ? lref_ : default_)) + >; + + template + struct flag_map { + static_assert(sizeof(T) < 0, + "Invalid argument passed to flag_map template."); + + static constexpr flags value = default_; + }; + + template<> struct flag_map { static constexpr flags value = default_; }; + template<> struct flag_map { static constexpr flags value = lref_; }; + template<> struct flag_map { static constexpr flags value = rref_; }; + template<> struct flag_map { static constexpr flags value = const_; }; + template<> struct flag_map { static constexpr flags value = const_ | lref_; }; + template<> struct flag_map { static constexpr flags value = const_ | rref_; }; + template<> struct flag_map { static constexpr flags value = volatile_; }; + template<> struct flag_map { static constexpr flags value = volatile_ | lref_; }; + template<> struct flag_map { static constexpr flags value = volatile_ | rref_; }; + template<> struct flag_map { static constexpr flags value = const_ | volatile_; }; + template<> struct flag_map { static constexpr flags value = const_ | volatile_ | lref_; }; + template<> struct flag_map { static constexpr flags value = const_ | volatile_ | rref_; }; + + template + class qualifier_traits { + + protected: + + static constexpr flags cv_flags = cv_of::value; + static constexpr flags ref_flags = ref_of::value; + static constexpr flags q_flags = cv_flags | ref_flags; + + public: + + using is_reference_qualified = std::integral_constant; + using is_lvalue_reference_qualified = std::integral_constant; + using is_rvalue_reference_qualified = std::integral_constant; + using is_const_qualified = std::integral_constant; + using is_volatile_qualified = std::integral_constant; + using is_cv_qualified = std::integral_constant; + }; + } +} +#endif \ No newline at end of file diff --git a/include/callable_traits/remove_duplicate_placeholders.hpp b/include/callable_traits/remove_duplicate_placeholders.hpp deleted file mode 100644 index b27563d..0000000 --- a/include/callable_traits/remove_duplicate_placeholders.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/*! -@copyright Barrett Adair 2016 - -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) -*/ - -#ifndef CALLABLE_TRAITS_REMOVE_DUPLICATE_PLACEHOLDERS_HPP -#define CALLABLE_TRAITS_REMOVE_DUPLICATE_PLACEHOLDERS_HPP - -namespace callable_traits { - - namespace detail { - - template - struct remove_duplicate_placeholders { - using type = std::tuple<>; - }; - - template - struct remove_duplicate_placeholders > { - using type = typename remove_duplicate_placeholders::type; - }; - - //if 1st and 2nd elements use the same placeholder index, remove the second element - template - struct remove_duplicate_placeholders { - using type = typename std::conditional< - PhRoute1::ph_value == PhRoute2::ph_value, - typename remove_duplicate_placeholders::type, - typename prepend::type>::type - >::type; - }; - - //base case - template - struct remove_duplicate_placeholders { - using type = typename std::conditional< - PhRoute1::ph_value == PhRoute2::ph_value, - std::tuple, - std::tuple - >::type; - }; - - //base case - template - struct remove_duplicate_placeholders { - using type = std::tuple; - }; - } -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/remove_reference_if_ptr.hpp b/include/callable_traits/remove_reference_if_ptr.hpp deleted file mode 100644 index a72f5ac..0000000 --- a/include/callable_traits/remove_reference_if_ptr.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/*! -@file - -@copyright Barrett Adair 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - -*/ - -#ifndef CALLABLE_TRAITS_REMOVE_REFERNCE_IF_PTR_HPP -#define CALLABLE_TRAITS_REMOVE_REFERNCE_IF_PTR_HPP - -#include - -namespace callable_traits { - - namespace detail { - - template - using remove_reference_if_ptr = typename std::conditional< - std::is_pointer::type>::value, - typename std::remove_reference::type, - T - >::type; - } -} - -#endif \ No newline at end of file diff --git a/include/callable_traits/set_function_qualifiers.hpp b/include/callable_traits/set_function_qualifiers.hpp index eae861a..f83aae8 100644 --- a/include/callable_traits/set_function_qualifiers.hpp +++ b/include/callable_traits/set_function_qualifiers.hpp @@ -10,8 +10,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef CALLABLE_TRAITS_SET_FUNCTION_QUALIFIERS_HPP #define CALLABLE_TRAITS_SET_FUNCTION_QUALIFIERS_HPP -#include -#include +#include #include #define CALLABLE_TRAITS_SET_FUNCTION_QUALIFIERS(QUAL) \ diff --git a/include/callable_traits/tags.hpp b/include/callable_traits/tags.hpp index 2743357..bbaff95 100644 --- a/include/callable_traits/tags.hpp +++ b/include/callable_traits/tags.hpp @@ -22,13 +22,6 @@ Distributed under the Boost Software License, Version 1.0. namespace callable_traits { namespace detail { - struct pmf_tag {}; - struct pmd_tag {}; - struct function_tag {}; - struct function_reference_tag : function_tag {}; - struct function_ptr_tag : function_tag {}; - struct function_object_tag {}; - struct ambiguous_function_object_tag : function_object_tag {}; struct dummy {}; } diff --git a/include/callable_traits/test_invoke.hpp b/include/callable_traits/test_invoke.hpp index 5ff1ac5..922b689 100644 --- a/include/callable_traits/test_invoke.hpp +++ b/include/callable_traits/test_invoke.hpp @@ -11,7 +11,8 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_DECLVOKE_HPP #include -#include +#include +#include #include #include @@ -22,13 +23,13 @@ namespace callable_traits { namespace detail { template - struct subst_success {}; + struct success {}; template>, typename IsSame = std::is_same>> using generalize_if_dissimilar = typename std::conditional< - IsBaseOf::value || IsSame::value, T, normalize_ptr_or_reference + IsBaseOf::value || IsSame::value, T, generalize >::type; template @@ -42,7 +43,7 @@ namespace callable_traits { template> auto operator()(P&& p, U&& u, Rgs&&... rgs) const -> - subst_success().*p)(std::forward(rgs)...))>; + success().*p)(std::forward(rgs)...))>; auto operator()(...) const -> substitution_failure; @@ -57,7 +58,7 @@ namespace callable_traits { template> auto operator()(P&& p, U&& u) const -> - subst_success().*p))>; + success().*p))>; auto operator()(...) const -> substitution_failure; @@ -68,9 +69,9 @@ namespace callable_traits { struct test_invoke { template> + typename U = unwrap_reference> auto operator()(T&& t, Rgs&&... rgs) const -> - subst_success()(std::forward(rgs)...))>; + success()(std::forward(rgs)...))>; auto operator()(...) const -> substitution_failure; diff --git a/include/callable_traits/traits.hpp b/include/callable_traits/traits.hpp index 0dec10f..0311c9d 100644 --- a/include/callable_traits/traits.hpp +++ b/include/callable_traits/traits.hpp @@ -11,15 +11,12 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_TRAITS_HPP -#include +#include #include -#include -#include #include #include #include #include -#include #include #include @@ -29,14 +26,21 @@ namespace callable_traits { namespace detail { + template + using remove_reference_if_ptr = typename std::conditional< + std::is_pointer::type>::value, + typename std::remove_reference::type, + T + >::type; + template using traits = typename disjunction< bind_expression_traits>, - function_object>, + function_object>, function>, pmf>, pmd>, - function_object> + function_object> >::traits; } } diff --git a/include/callable_traits/tuple_group_by.hpp b/include/callable_traits/tuple_group_by.hpp index fe9d262..05193db 100644 --- a/include/callable_traits/tuple_group_by.hpp +++ b/include/callable_traits/tuple_group_by.hpp @@ -9,7 +9,7 @@ Distributed under the Boost Software License, Version 1.0. #ifndef CALLABLE_TRAITS_TUPLE_GROUP_BY_HPP #define CALLABLE_TRAITS_TUPLE_GROUP_BY_HPP -#include +#include #include #include #include @@ -108,7 +108,7 @@ namespace callable_traits { using group_by_values = typename distinct_group_by_values::type; using type = typename group_by_impl< - sort_tuple, + tuple_sort, group_by_values, Pred, std::make_index_sequence::value> diff --git a/include/callable_traits/sort_tuple.hpp b/include/callable_traits/tuple_sort.hpp similarity index 98% rename from include/callable_traits/sort_tuple.hpp rename to include/callable_traits/tuple_sort.hpp index 94b1e6f..1727ddf 100644 --- a/include/callable_traits/sort_tuple.hpp +++ b/include/callable_traits/tuple_sort.hpp @@ -107,7 +107,7 @@ namespace callable_traits { }; template class Pred> - using sort_tuple = typename sort_impl>::type; + using tuple_sort = typename sort_impl>::type; } } diff --git a/include/callable_traits/unwrap_reference.hpp b/include/callable_traits/unwrap_reference.hpp new file mode 100644 index 0000000..5dfd909 --- /dev/null +++ b/include/callable_traits/unwrap_reference.hpp @@ -0,0 +1,35 @@ +/*! +@file + +@copyright Barrett Adair 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +*/ + +#ifndef CALLABLE_TRAITS_UNWRAP_REFERENCE_HPP +#define CALLABLE_TRAITS_UNWRAP_REFERENCE_HPP + +#include +#include + +namespace callable_traits { + + namespace detail { + + template + struct unwrap_reference_t { + using type = T; + }; + + template + struct unwrap_reference_t> { + using type = decltype(std::declval().get()); + }; + + template + using unwrap_reference = typename unwrap_reference_t::type; + } +} + +#endif \ No newline at end of file