From 36768287a58cf3e3d00affbf34b6fc36a96f1fcc Mon Sep 17 00:00:00 2001 From: badair Date: Mon, 28 Mar 2016 04:21:21 -0500 Subject: [PATCH] adding config.hpp, code cleanup --- include/callable_traits/bind_expression.hpp | 1 - include/callable_traits/callable_traits.hpp | 317 +---------------- .../callable_traits/categorize_bind_arg.hpp | 1 - .../callable_traits/{tags.hpp => config.hpp} | 16 +- include/callable_traits/function.hpp | 6 +- include/callable_traits/function_object.hpp | 1 - include/callable_traits/interface.hpp | 320 ++++++++++++++++++ .../member_pointer_utilities.hpp | 2 - include/callable_traits/pmf.hpp | 7 +- .../set_function_qualifiers.hpp | 2 +- 10 files changed, 343 insertions(+), 330 deletions(-) rename include/callable_traits/{tags.hpp => config.hpp} (71%) create mode 100644 include/callable_traits/interface.hpp diff --git a/include/callable_traits/bind_expression.hpp b/include/callable_traits/bind_expression.hpp index a1f3057..90306e6 100644 --- a/include/callable_traits/bind_expression.hpp +++ b/include/callable_traits/bind_expression.hpp @@ -13,7 +13,6 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include #include #include #include diff --git a/include/callable_traits/callable_traits.hpp b/include/callable_traits/callable_traits.hpp index cd8d434..96631a4 100644 --- a/include/callable_traits/callable_traits.hpp +++ b/include/callable_traits/callable_traits.hpp @@ -7,8 +7,8 @@ Distributed under the Boost Software License, Version 1.0. */ -#ifndef CALLABLE_TRAITS_HPP -#define CALLABLE_TRAITS_HPP +#ifndef CALLABLE_TRAITS_CALLABLE_TRAITS_HPP +#define CALLABLE_TRAITS_CALLABLE_TRAITS_HPP #ifdef _MSVC_VER #pragma warning(push) @@ -17,318 +17,7 @@ Distributed under the Boost Software License, Version 1.0. #pragma warning(disable : 4503) #endif //ifdef _MSVC_VER -#include -#include -#include -#include -#include -#include -#include -#include -#include -#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; - - template - using qualified_signature = typename detail::traits::abominable_type; - - template - using result_of = typename detail::traits::return_type; - - template - using remove_const_qualifier = - typename detail::traits::remove_const; - - template - using remove_volatile_qualifier = - typename detail::traits::remove_volatile; - - template - using remove_cv_qualifiers = - typename detail::traits::remove_cv; - - template - using remove_reference_qualifier = - typename detail::traits::remove_reference; - - template - using remove_varargs = - typename detail::traits::remove_varargs; - - template - using add_const_qualifier = - typename detail::traits::add_const; - - template - using add_volatile_qualifier = - typename detail::traits::add_volatile; - - template - using add_cv_qualifiers = - typename detail::traits::add_cv; - - template - using add_lvalue_qualifier = - typename detail::traits::add_lvalue_reference; - - template - using add_rvalue_qualifier = - typename detail::traits::add_rvalue_reference; - - template - using add_varargs = - typename detail::traits::add_varargs; - } - - namespace detail { - - template - using if_valid = typename std::enable_if< - !std::is_same::value - && !std::is_same::value, - T - >::type; - } - - template - using args = detail::if_valid>; - - template - using arg_at = detail::if_valid>::type>; - - template - using signature = detail::if_valid>; - - template - using qualified_signature = detail::if_valid>; - - template - using result_of = detail::if_valid>; - - template - using remove_const_qualifier = detail::if_valid>; - - template - using remove_volatile_qualifier = detail::if_valid>; - - template - using remove_cv_qualifiers = detail::if_valid>; - - template - using remove_reference_qualifier = detail::if_valid>; - - template - using add_const_qualifier = detail::if_valid>; - - template - using add_volatile_qualifier = detail::if_valid>; - - template - using add_cv_qualifiers = detail::if_valid>; - - template - using add_lvalue_qualifier = detail::if_valid>; - - template - using add_rvalue_qualifier = detail::if_valid>; - - template - using add_varargs = detail::if_valid>; - - template - using remove_varargs = detail::if_valid>; - - template - inline constexpr auto - can_invoke(T&& t, Args&&... args) { - using traits = detail::traits; - using test = detail::test_invoke; - using result = decltype(test{}(::std::forward(t), ::std::forward(args)...)); - using failure = detail::substitution_failure; - using is_invalid_invoke = std::is_same; - return std::integral_constant{}; - } - - template - inline constexpr auto - is_overloaded(T&&) { - return typename detail::traits::is_ambiguous{}; - } - - template - inline constexpr auto - is_overloaded() { - return typename detail::traits::is_ambiguous{}; - } - - template - inline constexpr auto - has_varargs(T&&) { - return typename detail::traits::has_varargs{}; - } - - template - inline constexpr auto - has_varargs() { - return typename detail::traits::has_varargs{}; - } - - template< std::size_t SearchLimit = constants::arity_search_limit, typename T> - inline constexpr auto - min_arity(T&&) { - using traits = detail::traits; - return detail::min_arity_t{}; - } - - template - inline constexpr auto - min_arity() { - using traits = detail::traits; - return detail::min_arity_t{}; - } - - template - inline constexpr auto - max_arity(T&&) { - return detail::max_arity_t, SearchLimit>{}; - } - - template - inline constexpr auto - max_arity() { - return detail::max_arity_t, SearchLimit>{}; - } - - template - inline constexpr auto - arity(T&&) { - return detail::arity_t>{}; - } - - template - inline constexpr auto - arity() { - return detail::arity_t>{}; - } - - template - inline constexpr auto - bind_expr(T, Args...) -> detail::bind_expression { - return{}; - } - - template - inline constexpr auto - is_unqualified() { - return typename detail::traits::is_unqualified{}; - } - - template - inline constexpr auto - is_unqualified(T&&) { - return typename detail::traits::is_unqualified{}; - } - - template - inline constexpr auto - is_const_qualified() { - return typename detail::traits::is_const_qualified{}; - } - - template - inline constexpr auto - is_const_qualified(T&&) { - return typename detail::traits::is_const_qualified{}; - } - - template - inline constexpr auto - is_cv_qualified() { - return typename detail::traits::is_cv_qualified{}; - } - - template - inline constexpr auto - is_cv_qualified(T&&) { - return typename detail::traits::is_cv_qualified{}; - } - - template - inline constexpr auto - is_volatile_qualified() { - return typename detail::traits::is_volatile_qualified{}; - } - - template - inline constexpr auto - is_volatile_qualified(T&&) { - return typename detail::traits::is_volatile_qualified{}; - } - - template - inline constexpr auto - is_reference_qualified() { - return typename detail::traits::is_reference_qualified{}; - } - - template - inline constexpr auto - is_reference_qualified(T&&) { - return typename detail::traits::is_reference_qualified{}; - } - - template - inline constexpr auto - is_lvalue_reference_qualified() { - return typename detail::traits::is_lvalue_reference_qualified{}; - } - - template - inline constexpr auto - is_lvalue_reference_qualified(T&&) { - return typename detail::traits::is_lvalue_reference_qualified{}; - } - - template - inline constexpr auto - is_rvalue_reference_qualified() { - return typename detail::traits::is_rvalue_reference_qualified{}; - } - - template - inline constexpr auto - is_rvalue_reference_qualified(T&&) { - return typename detail::traits::is_rvalue_reference_qualified{}; - } -} +#include #ifdef _MSVC_VER #pragma warning(pop) diff --git a/include/callable_traits/categorize_bind_arg.hpp b/include/callable_traits/categorize_bind_arg.hpp index d47ba67..164d129 100644 --- a/include/callable_traits/categorize_bind_arg.hpp +++ b/include/callable_traits/categorize_bind_arg.hpp @@ -11,7 +11,6 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include -#include #include namespace callable_traits { diff --git a/include/callable_traits/tags.hpp b/include/callable_traits/config.hpp similarity index 71% rename from include/callable_traits/tags.hpp rename to include/callable_traits/config.hpp index bbaff95..1d3c3dc 100644 --- a/include/callable_traits/tags.hpp +++ b/include/callable_traits/config.hpp @@ -7,8 +7,8 @@ Distributed under the Boost Software License, Version 1.0. */ -#ifndef CALLABLE_TRAITS_TAGS_HPP -#define CALLABLE_TRAITS_TAGS_HPP +#ifndef CALLABLE_TRAITS_CONFIG_HPP +#define CALLABLE_TRAITS_CONFIG_HPP #define CALLABLE_TRAITS_EMPTY_ #define CALLABLE_TRAITS_EMPTY CALLABLE_TRAITS_EMPTY_ @@ -19,10 +19,19 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_VARARGS_CC #endif //_MSC_VER +#include + namespace callable_traits { namespace detail { + struct dummy {}; + + template + struct value_type_pair { + using type = T; + static constexpr const bool value = Value; + }; } struct constants { @@ -33,5 +42,4 @@ namespace callable_traits { struct unknown { unknown() = delete; }; } - -#endif \ No newline at end of file +#endif diff --git a/include/callable_traits/function.hpp b/include/callable_traits/function.hpp index 386eaa0..b0ccbac 100644 --- a/include/callable_traits/function.hpp +++ b/include/callable_traits/function.hpp @@ -11,11 +11,11 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_FUNCTION_HPP #include -#include #include #include #include #include +#include #include @@ -162,6 +162,8 @@ namespace callable_traits { CALLABLE_TRAITS_SPECIALIZE_FUNCTION(const &&); CALLABLE_TRAITS_SPECIALIZE_FUNCTION(volatile &&); CALLABLE_TRAITS_SPECIALIZE_FUNCTION(const volatile &&); + +#undef CLBL_SPECIALIZE_FUNCTION template struct function : function { @@ -211,6 +213,4 @@ namespace callable_traits { } } -#undef CLBL_SPECIALIZE_FUNCTION - #endif \ No newline at end of file diff --git a/include/callable_traits/function_object.hpp b/include/callable_traits/function_object.hpp index e08bdb7..1ae5f3c 100644 --- a/include/callable_traits/function_object.hpp +++ b/include/callable_traits/function_object.hpp @@ -12,7 +12,6 @@ Distributed under the Boost Software License, Version 1.0. #include #include -#include #include diff --git a/include/callable_traits/interface.hpp b/include/callable_traits/interface.hpp new file mode 100644 index 0000000..89daa4a --- /dev/null +++ b/include/callable_traits/interface.hpp @@ -0,0 +1,320 @@ +/*! +@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_INTERFACE_HPP +#define CALLABLE_TRAITS_INTERFACE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace callable_traits { + + 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; + + template + using qualified_signature = typename detail::traits::abominable_type; + + template + using result_of = typename detail::traits::return_type; + + template + using remove_const_qualifier = + typename detail::traits::remove_const; + + template + using remove_volatile_qualifier = + typename detail::traits::remove_volatile; + + template + using remove_cv_qualifiers = + typename detail::traits::remove_cv; + + template + using remove_reference_qualifier = + typename detail::traits::remove_reference; + + template + using remove_varargs = + typename detail::traits::remove_varargs; + + template + using add_const_qualifier = + typename detail::traits::add_const; + + template + using add_volatile_qualifier = + typename detail::traits::add_volatile; + + template + using add_cv_qualifiers = + typename detail::traits::add_cv; + + template + using add_lvalue_qualifier = + typename detail::traits::add_lvalue_reference; + + template + using add_rvalue_qualifier = + typename detail::traits::add_rvalue_reference; + + template + using add_varargs = + typename detail::traits::add_varargs; + } + + namespace detail { + + template + using if_valid = typename std::enable_if< + !std::is_same::value + && !std::is_same::value, + T + >::type; + } + + template + using args = detail::if_valid>; + + template + using arg_at = detail::if_valid>::type>; + + template + using signature = detail::if_valid>; + + template + using qualified_signature = detail::if_valid>; + + template + using result_of = detail::if_valid>; + + template + using remove_const_qualifier = detail::if_valid>; + + template + using remove_volatile_qualifier = detail::if_valid>; + + template + using remove_cv_qualifiers = detail::if_valid>; + + template + using remove_reference_qualifier = detail::if_valid>; + + template + using add_const_qualifier = detail::if_valid>; + + template + using add_volatile_qualifier = detail::if_valid>; + + template + using add_cv_qualifiers = detail::if_valid>; + + template + using add_lvalue_qualifier = detail::if_valid>; + + template + using add_rvalue_qualifier = detail::if_valid>; + + template + using add_varargs = detail::if_valid>; + + template + using remove_varargs = detail::if_valid>; + + template + inline constexpr auto + can_invoke(T&& t, Args&&... args) { + using traits = detail::traits; + using test = detail::test_invoke; + using result = decltype(test{}(::std::forward(t), ::std::forward(args)...)); + using failure = detail::substitution_failure; + using is_invalid_invoke = std::is_same; + return std::integral_constant{}; + } + + template + inline constexpr auto + is_overloaded(T&&) { + return typename detail::traits::is_ambiguous{}; + } + + template + inline constexpr auto + is_overloaded() { + return typename detail::traits::is_ambiguous{}; + } + + template + inline constexpr auto + has_varargs(T&&) { + return typename detail::traits::has_varargs{}; + } + + template + inline constexpr auto + has_varargs() { + return typename detail::traits::has_varargs{}; + } + + template< std::size_t SearchLimit = constants::arity_search_limit, typename T> + inline constexpr auto + min_arity(T&&) { + using traits = detail::traits; + return detail::min_arity_t{}; + } + + template + inline constexpr auto + min_arity() { + using traits = detail::traits; + return detail::min_arity_t{}; + } + + template + inline constexpr auto + max_arity(T&&) { + return detail::max_arity_t, SearchLimit>{}; + } + + template + inline constexpr auto + max_arity() { + return detail::max_arity_t, SearchLimit>{}; + } + + template + inline constexpr auto + arity(T&&) { + return detail::arity_t>{}; + } + + template + inline constexpr auto + arity() { + return detail::arity_t>{}; + } + + template + inline constexpr auto + bind_expr(T, Args...) -> detail::bind_expression { + return{}; + } + + template + inline constexpr auto + is_unqualified() { + return typename detail::traits::is_unqualified{}; + } + + template + inline constexpr auto + is_unqualified(T&&) { + return typename detail::traits::is_unqualified{}; + } + + template + inline constexpr auto + is_const_qualified() { + return typename detail::traits::is_const_qualified{}; + } + + template + inline constexpr auto + is_const_qualified(T&&) { + return typename detail::traits::is_const_qualified{}; + } + + template + inline constexpr auto + is_cv_qualified() { + return typename detail::traits::is_cv_qualified{}; + } + + template + inline constexpr auto + is_cv_qualified(T&&) { + return typename detail::traits::is_cv_qualified{}; + } + + template + inline constexpr auto + is_volatile_qualified() { + return typename detail::traits::is_volatile_qualified{}; + } + + template + inline constexpr auto + is_volatile_qualified(T&&) { + return typename detail::traits::is_volatile_qualified{}; + } + + template + inline constexpr auto + is_reference_qualified() { + return typename detail::traits::is_reference_qualified{}; + } + + template + inline constexpr auto + is_reference_qualified(T&&) { + return typename detail::traits::is_reference_qualified{}; + } + + template + inline constexpr auto + is_lvalue_reference_qualified() { + return typename detail::traits::is_lvalue_reference_qualified{}; + } + + template + inline constexpr auto + is_lvalue_reference_qualified(T&&) { + return typename detail::traits::is_lvalue_reference_qualified{}; + } + + template + inline constexpr auto + is_rvalue_reference_qualified() { + return typename detail::traits::is_rvalue_reference_qualified{}; + } + + template + inline constexpr auto + is_rvalue_reference_qualified(T&&) { + return typename detail::traits::is_rvalue_reference_qualified{}; + } +} + +#ifdef _MSVC_VER +#pragma warning(pop) +#endif //ifdef _MSVC_VER + +#endif diff --git a/include/callable_traits/member_pointer_utilities.hpp b/include/callable_traits/member_pointer_utilities.hpp index f09cda4..d84a9a3 100644 --- a/include/callable_traits/member_pointer_utilities.hpp +++ b/include/callable_traits/member_pointer_utilities.hpp @@ -10,8 +10,6 @@ Distributed under the Boost Software License, Version 1.0. #ifndef MEMBER_POINTER_UTILITIES_HPP #define MEMBER_POINTER_UTILITIES_HPP -#include - namespace callable_traits { namespace detail { diff --git a/include/callable_traits/pmf.hpp b/include/callable_traits/pmf.hpp index 70f3ff6..0f6b364 100644 --- a/include/callable_traits/pmf.hpp +++ b/include/callable_traits/pmf.hpp @@ -11,8 +11,8 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_PMF_HPP #include -#include #include +#include #include #define CALLABLE_TRAITS_SPECIALIZE_PMF(QUAL) \ @@ -160,9 +160,10 @@ namespace callable_traits { CALLABLE_TRAITS_SPECIALIZE_PMF(const &&); CALLABLE_TRAITS_SPECIALIZE_PMF(volatile &&); CALLABLE_TRAITS_SPECIALIZE_PMF(const volatile &&); + +#undef CALLABLE_TRAITS_SPECIALIZE_PMF + } } -#undef CALLABLE_TRAITS_SPECIALIZE_PMF - #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 f83aae8..932d6af 100644 --- a/include/callable_traits/set_function_qualifiers.hpp +++ b/include/callable_traits/set_function_qualifiers.hpp @@ -11,7 +11,7 @@ Distributed under the Boost Software License, Version 1.0. #define CALLABLE_TRAITS_SET_FUNCTION_QUALIFIERS_HPP #include -#include +#include #define CALLABLE_TRAITS_SET_FUNCTION_QUALIFIERS(QUAL) \ template \