tentatively adding more features

This commit is contained in:
badair
2016-04-29 03:51:24 -05:00
parent b033bd761d
commit 6497299206
19 changed files with 385 additions and 27 deletions

View File

@@ -20,17 +20,17 @@ namespace callable_traits {
struct args_error {
static_assert(Sfinae,
"Could not determine the arguments for "
"Could not determine the parameters for "
"T in callable_traits::args<T>. Note: "
"If T is the type of a generic lambda or "
" overloaded/templated function object, "
"the arguments cannot be determined. ");
"the parameters cannot be determined. ");
};
}
namespace permissive {
// returns callable_traits::invalid_type if argument types
// returns callable_traits::invalid_type if parameter types
// cannot be determined
template<typename T>
using args = typename detail::traits<T>::arg_types;
@@ -50,4 +50,4 @@ namespace callable_traits {
detail::args_error<true>>;
}
#endif
#endif //#ifndef CALLABLE_TRAITS_ARGS_HPP

View File

@@ -22,15 +22,19 @@ Distributed under the Boost Software License, Version 1.0.
#include <callable_traits/apply_return.hpp>
#include <callable_traits/arg_at.hpp>
#include <callable_traits/args.hpp>
#include <callable_traits/invoke_args.hpp>
#include <callable_traits/arity.hpp>
#include <callable_traits/bind.hpp>
#include <callable_traits/copy_qualifiers.hpp>
#include <callable_traits/can_invoke.hpp>
#include <callable_traits/can_invoke_constexpr.hpp>
#include <callable_traits/clear_args.hpp>
#include <callable_traits/expand_args.hpp>
#include <callable_traits/expand_invoke_args.hpp>
#include <callable_traits/function_type.hpp>
#include <callable_traits/has_calling_convention.hpp>
#include <callable_traits/has_member_qualifiers.hpp>
#include <callable_traits/has_same_qualifiers.hpp>
#include <callable_traits/has_varargs.hpp>
#include <callable_traits/has_void_return.hpp>
#include <callable_traits/insert_at.hpp>
@@ -43,6 +47,8 @@ Distributed under the Boost Software License, Version 1.0.
#include <callable_traits/max_arity.hpp>
#include <callable_traits/min_arity.hpp>
#include <callable_traits/overwrite_at.hpp>
#include <callable_traits/parent_class_of.hpp>
#include <callable_traits/qualified_parent_class_of.hpp>
#include <callable_traits/pop_back.hpp>
#include <callable_traits/pop_front.hpp>
#include <callable_traits/push_back.hpp>

View File

@@ -0,0 +1,51 @@
/*!
@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_COPY_QUALIFIERS_HPP
#define CALLABLE_TRAITS_COPY_QUALIFIERS_HPP
#include <callable_traits/detail/required_definitions.hpp>
#include <callable_traits/detail/copy_qualifiers_impl.hpp>
namespace callable_traits {
namespace detail {
template<bool Sfinae>
struct copy_qualifiers_error {
static_assert(Sfinae,
"TODO: error message for callable_traits::copy_qualifiers");
};
}
namespace permissive {
// returns callable_traits::invalid_type if parameter types
// cannot be determined
template<typename To, typename From>
using copy_qualifiers =
typename detail::copy_qualifiers_impl<detail::traits<To>, detail::traits<From>>::type;
}
namespace verbose {
template<typename To, typename From>
using copy_qualifiers = detail::fail_if_invalid<
typename detail::copy_qualifiers_impl<detail::traits<To>, detail::traits<From>>::type,
detail::invoke_args_error<false>>;
}
template<typename To, typename From>
using copy_qualifiers = detail::fail_if_invalid<
typename detail::copy_qualifiers_impl<detail::traits<To>, detail::traits<From>>::type,
detail::invoke_args_error<true>>;
}
#endif //#ifndef CALLABLE_TRAITS_COPY_QUALIFIERS_HPP

View File

@@ -43,6 +43,10 @@ namespace callable_traits {
template<template<class...> class Container>
using expand_args =
typename bind_expr_detail::expand_bind_args<arg_types, Container>::type;
template<template<class...> class Container>
using expand_invoke_args =
typename bind_expr_detail::expand_bind_args<arg_types, Container>::type;
};
}
}

View File

@@ -0,0 +1,38 @@
/*!
@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_DETAIL_COPY_QUALIFIERS_IMPL_HPP
#define CALLABLE_TRAITS_DETAIL_COPY_QUALIFIERS_IMPL_HPP
#include <callable_traits/detail/set_function_qualifiers.hpp>
namespace callable_traits {
namespace detail {
template<typename ToTraits, typename FromTraits,
bool IsSignature = can_accept_member_qualifiers<ToTraits>::value
&& can_accept_member_qualifiers<FromTraits>::value>
struct copy_qualifiers_impl;
template<typename ToTraits, typename FromTraits>
struct copy_qualifiers_impl<ToTraits, FromTraits, true> {
using type = typename ToTraits::template set_qualifiers<FromTraits::q_flags>;
};
template<typename ToTraits, typename FromTraits>
struct copy_qualifiers_impl<ToTraits, FromTraits, false> {
using type = set_other_qualifiers<FromTraits::q_flags, typename ToTraits::type>;
};
}
}
#endif //#ifndef CALLABLE_TRAITS_DETAIL_COPY_QUALIFIERS_IMPL_HPP

View File

@@ -52,13 +52,9 @@ namespace callable_traits {
// std::true_type for plain function types only
using is_function = std::false_type;
// std::true_type for plain function types with qualifiers
// std::true_type for function types with qualifiers
using has_member_qualifiers_function = std::false_type;
// std::true_type for function pointers, function references
// and plain function types
using is_functionish = std::false_type;
// std::true_type for callables with C-style variadics
using has_varargs = std::false_type;
@@ -159,6 +155,9 @@ namespace callable_traits {
template<template<class...> class Container>
using expand_args = invalid_type;
template<template<class...> class Container>
using expand_invoke_args = invalid_type;
using clear_args = invalid_type;
template<typename... NewArgs>

View File

@@ -133,16 +133,12 @@ namespace callable_traits {
template<> struct flag_map<int const volatile &&> { static constexpr flags value = const_ | volatile_ | rref_; };
template<typename T>
class qualifier_traits {
protected:
struct qualifier_traits {
static constexpr flags cv_flags = cv_of<T>::value;
static constexpr flags ref_flags = ref_of<T>::value;
static constexpr flags q_flags = cv_flags | ref_flags;
public:
using has_member_qualifiers = std::integral_constant<bool, q_flags != default_>;
using is_const_member = std::integral_constant<bool, 0 < (cv_flags & const_)>;
using is_volatile_member = std::integral_constant<bool, 0 < (cv_flags & volatile_)>;

View File

@@ -16,16 +16,23 @@ Distributed under the Boost Software License, Version 1.0.
#define CALLABLE_TRAITS_SET_FUNCTION_QUALIFIERS(QUAL) \
template<typename Return, typename... Args> \
struct set_function_qualifiers_t < \
flag_map<int QUAL>::value, Return, Args... \
> { \
flag_map<int QUAL>::value, Return, Args...> { \
\
using type = Return(Args...) QUAL; \
}; \
\
template<typename Return, typename... Args> \
struct set_varargs_function_qualifiers_t < \
flag_map<int QUAL>::value, Return, Args... \
> { \
flag_map<int QUAL>::value, Return, Args...> { \
\
using type = Return(Args..., ...) QUAL; \
}; \
\
template<typename T> \
struct set_other_qualifiers_t < \
flag_map<int QUAL>::value, T> { \
\
using type = T QUAL; \
} \
/**/
@@ -43,6 +50,11 @@ namespace callable_traits {
using type = Return(Args..., ...);
};
template<flags Applied, typename T>
struct set_other_qualifiers_t {
using type = T;
};
#ifndef CALLABLE_TRAITS_DISABLE_ABOMINABLE_FUNCTIONS
CALLABLE_TRAITS_SET_FUNCTION_QUALIFIERS(const);
@@ -70,6 +82,10 @@ namespace callable_traits {
template<flags Flags, typename... Ts>
using set_varargs_function_qualifiers =
typename set_varargs_function_qualifiers_t<Flags, Ts...>::type;
template<flags Flags, typename T>
using set_other_qualifiers =
typename set_other_qualifiers_t<Flags, T>::type;
}
}

View File

@@ -16,7 +16,6 @@ struct function<T, Return(Args...) CALLABLE_TRAITS_INCLUDE_QUALIFIERS>
static constexpr bool value = true;
using is_function = std::true_type;
using is_functionish = std::true_type;
using traits = function;
using return_type = Return;
using arg_types = std::tuple<Args...>;
@@ -66,6 +65,9 @@ struct function<T, Return(Args...) CALLABLE_TRAITS_INCLUDE_QUALIFIERS>
template<template<class...> class Container>
using expand_args = Container<Args...>;
template<template<class...> class Container>
using expand_invoke_args = Container<Args...>;
using clear_args = Return() CALLABLE_TRAITS_INCLUDE_QUALIFIERS;
#undef CALLABLE_TRAITS_BEGIN_PACK_MANIP
@@ -89,7 +91,6 @@ struct function<T, Return (Args..., ...) CALLABLE_TRAITS_INCLUDE_QUALIFIERS>
using has_varargs = std::true_type;
using is_function = std::true_type;
using is_functionish = std::true_type;
using traits = function;
using return_type = Return;
using arg_types = std::tuple<Args...>;
@@ -137,6 +138,9 @@ struct function<T, Return (Args..., ...) CALLABLE_TRAITS_INCLUDE_QUALIFIERS>
template<template<class...> class Container>
using expand_args = Container<Args...>;
template<template<class...> class Container>
using expand_invoke_args = Container<Args...>;
using clear_args = Return() CALLABLE_TRAITS_INCLUDE_QUALIFIERS;
#define CALLABLE_TRAITS_BEGIN_PACK_MANIP Return(

View File

@@ -27,7 +27,6 @@ struct function<OriginalType, CALLABLE_TRAITS_ST Return(CALLABLE_TRAITS_CC *)(Ar
static constexpr bool value = true;
using is_function = std::true_type;
using is_functionish = std::true_type;
using traits = function;
using return_type = Return;
using arg_types = std::tuple<Args...>;

View File

@@ -27,7 +27,6 @@ struct function<OriginalType, CALLABLE_TRAITS_ST Return(CALLABLE_TRAITS_VARARGS_
static constexpr bool value = true;
using is_function = std::true_type;
using is_functionish = std::true_type;
using has_varargs = std::true_type;
using traits = function;
using return_type = Return;
@@ -66,6 +65,9 @@ struct function<OriginalType, CALLABLE_TRAITS_ST Return(CALLABLE_TRAITS_VARARGS_
template<template<class...> class Container>
using expand_args = Container<Args...>;
template<template<class...> class Container>
using expand_invoke_args = Container<Args...>;
using clear_args = typename copy_cvr<
CALLABLE_TRAITS_ST Return(CALLABLE_TRAITS_VARARGS_CC *)(),
OriginalType

View File

@@ -105,6 +105,9 @@ struct pmf<OriginalType,
template<template<class...> class Container>
using expand_args = Container<Args...>;
template<template<class...> class Container>
using expand_invoke_args = Container<invoke_type, Args...>;
#undef CALLABLE_TRAITS_BEGIN_PACK_MANIP
#undef CALLABLE_TRAITS_ARGS_PACK
#undef CALLABLE_TRAITS_END_PACK_MANIP

View File

@@ -109,6 +109,9 @@ struct pmf<OriginalType, Return(CALLABLE_TRAITS_VARARGS_CC T::*)(Args..., ...) C
template<template<class...> class Container>
using expand_args = Container<Args...>;
template<template<class...> class Container>
using expand_invoke_args = Container<invoke_type, Args...>;
using clear_args = typename copy_cvr<
Return(CALLABLE_TRAITS_VARARGS_CC T::*)() CALLABLE_TRAITS_INCLUDE_QUALIFIERS,
OriginalType

View File

@@ -18,11 +18,11 @@ Distributed under the Boost Software License, Version 1.0.
namespace callable_traits {
struct constants {
static constexpr std::size_t arity_search_limit = CALLABLE_TRAITS_ARITY_SEARCH_LIMIT;
};
struct constants {
static constexpr std::size_t arity_search_limit = CALLABLE_TRAITS_ARITY_SEARCH_LIMIT;
};
struct invalid_type { invalid_type() = delete; };
struct invalid_type { invalid_type() = delete; };
namespace detail {
@@ -131,7 +131,10 @@ struct invalid_type { invalid_type() = delete; };
template<typename T, typename Class>
using add_member_pointer = T Class::*;
template<typename Traits>
using can_accept_member_qualifiers = std::integral_constant<bool,
Traits::is_function::value || Traits::has_member_qualifiers_function::value>;
namespace util_detail {
template<typename T>

View File

@@ -0,0 +1,48 @@
/*!
@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_EXPAND_INVOKE_ARGS_HPP
#define CALLABLE_TRAITS_EXPAND_INVOKE_ARGS_HPP
#include <callable_traits/detail/required_definitions.hpp>
namespace callable_traits {
namespace detail {
template<bool Sfinae>
struct expand_invoke_args_error {
static_assert(Sfinae,
"callable_traits::expand_invoke_args<T, U> is not a valid operation.");
};
}
namespace permissive {
// returns callable_traits::invalid_type if argument types cannot be determined
template<typename T, template<class...> class Container>
using expand_invoke_args = typename detail::traits<T>::template expand_invoke_args<Container>;
}
namespace verbose {
template<typename T, template<class...> class Container>
using expand_invoke_args = detail::fail_if_invalid<
typename detail::traits<T>::template expand_invoke_args<Container>,
detail::expand_invoke_args_error<false>>;
}
template<typename T, template<class...> class Container>
using expand_invoke_args = detail::fail_if_invalid<
typename detail::traits<T>::template expand_invoke_args<Container>,
detail::expand_invoke_args_error<true>>;
}
#endif //#ifndef CALLABLE_TRAITS_EXPAND_INVOKE_ARGS_HPP

View File

@@ -0,0 +1,33 @@
/*!
@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_SAME_QUALIFIERS_HPP
#define CALLABLE_TRAITS_HAS_SAME_QUALIFIERS_HPP
#include <callable_traits/detail/required_definitions.hpp>
#include <callable_traits/copy_qualifiers.hpp>
namespace callable_traits {
template<typename T, typename Callable>
inline constexpr auto
has_same_qualifiers() {
return typename std::is_same<T, copy_qualifiers<T, Callable>>::type{};
}
template<typename T, typename Callable>
inline constexpr auto
has_same_qualifiers(T&&, Callable&&) {
return has_same_qualifiers<T&&, Callable&&>();
}
}
#endif //#ifndef CALLABLE_TRAITS_COPY_QUALIFIERS_HPP

View File

@@ -0,0 +1,53 @@
/*!
@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_INVOKE_ARGS_HPP
#define CALLABLE_TRAITS_INVOKE_ARGS_HPP
#include <callable_traits/detail/required_definitions.hpp>
namespace callable_traits {
namespace detail {
template<bool Sfinae>
struct invoke_args_error {
static_assert(Sfinae,
"Could not determine the parameters for "
"T in callable_traits::args<T>. Note: "
"If T is the type of a generic lambda or "
" overloaded/templated function object, "
"the parameters cannot be determined. ");
};
}
namespace permissive {
// returns callable_traits::invalid_type if parameter types
// cannot be determined
template<typename T>
using invoke_args = typename detail::traits<T>::invoke_arg_types;
}
namespace verbose {
template<typename T>
using invoke_args = detail::fail_if_invalid<
typename detail::traits<T>::invoke_arg_types,
detail::invoke_args_error<false>>;
}
template<typename T>
using invoke_args = detail::fail_if_invalid<
typename detail::traits<T>::invoke_arg_types,
detail::invoke_args_error<true>>;
}
#endif //#ifndef CALLABLE_TRAITS_INVOKE_ARGS_HPP

View File

@@ -0,0 +1,50 @@
/*!
@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_PARENT_CLASS_OF_HPP
#define CALLABLE_TRAITS_PARENT_CLASS_OF_HPP
#include <callable_traits/detail/required_definitions.hpp>
namespace callable_traits {
namespace detail {
template<bool Sfinae>
struct parent_class_of_error {
static_assert(Sfinae,
"TODO: error message for callable_traits::parent_class_of");
};
}
namespace permissive {
// returns callable_traits::invalid_type if parameter types
// cannot be determined
template<typename T>
using parent_class_of =
typename detail::traits<T>::class_type;
}
namespace verbose {
template<typename T>
using parent_class_of = detail::fail_if_invalid<
typename detail::traits<T>::class_type,
detail::invoke_args_error<false>>;
}
template<typename T>
using parent_class_of = detail::fail_if_invalid<
typename detail::traits<T>::class_type,
detail::invoke_args_error<true>>;
}
#endif //#ifndef CALLABLE_TRAITS_PARENT_CLASS_OF_HPP

View File

@@ -0,0 +1,50 @@
/*!
@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_QUALIFIED_PARENT_CLASS_OF_HPP
#define CALLABLE_TRAITS_QUALIFIED_PARENT_CLASS_OF_HPP
#include <callable_traits/detail/required_definitions.hpp>
namespace callable_traits {
namespace detail {
template<bool Sfinae>
struct qualified_parent_class_of_error {
static_assert(Sfinae,
"TODO: error message for callable_traits::qualified_parent_class_of");
};
}
namespace permissive {
// returns callable_traits::invalid_type if parameter types
// cannot be determined
template<typename T>
using qualified_parent_class_of =
typename detail::traits<T>::invoke_type;
}
namespace verbose {
template<typename T>
using qualified_parent_class_of = detail::fail_if_invalid<
typename detail::traits<T>::invoke_type,
detail::invoke_args_error<false>>;
}
template<typename T>
using qualified_parent_class_of = detail::fail_if_invalid<
typename detail::traits<T>::invoke_type,
detail::invoke_args_error<true>>;
}
#endif //#ifndef CALLABLE_TRAITS_QUALIFIED_PARENT_CLASS_OF_HPP