diff --git a/sprout/type_traits/detail/invoke.hpp b/sprout/type_traits/detail/invoke.hpp new file mode 100644 index 00000000..45267ffb --- /dev/null +++ b/sprout/type_traits/detail/invoke.hpp @@ -0,0 +1,73 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_DETAIL_INVOKE_HPP +#define SPROUT_TYPE_TRAITS_DETAIL_INVOKE_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace detail { + template + inline SPROUT_CONSTEXPR decltype(std::declval()(std::declval()...)) + invoke(F&&, Args&&...) SPROUT_NOEXCEPT_IF_EXPR(std::declval()(std::declval()...)); + + template + inline SPROUT_CONSTEXPR decltype(std::declval().*(std::declval())) + invoke(T Base::*, Derived&&) SPROUT_NOEXCEPT_IF_EXPR(std::declval().*(std::declval())); + + template + inline SPROUT_CONSTEXPR decltype((*std::declval()).*(std::declval())) + invoke(PMD&&, Pointer&&) SPROUT_NOEXCEPT_IF_EXPR((*std::declval()).*(std::declval())); + + template + inline SPROUT_CONSTEXPR decltype((std::declval().*(std::declval()))(std::declval()...)) + invoke(T Base::*, Derived&&, Args&&...) SPROUT_NOEXCEPT_IF_EXPR((std::declval().*(std::declval()))(std::declval()...)); + + template + inline SPROUT_CONSTEXPR decltype(((*std::declval()).*(std::declval()))(std::declval()...)) + invoke(PMF&& pmf, Pointer&& ptr, Args&&... args) SPROUT_NOEXCEPT_IF_EXPR(((*std::declval()).*(std::declval()))(std::declval()...)); + + template + inline SPROUT_CONSTEXPR R + invoke(F&&, Args&&...) SPROUT_NOEXCEPT_IF_EXPR(R(std::declval()(std::declval()...))); + + template + inline SPROUT_CONSTEXPR decltype(R(std::declval().*(std::declval()))) + invoke(T Base::*, Derived&&) SPROUT_NOEXCEPT_IF_EXPR(R(std::declval().*(std::declval()))); + + template + inline SPROUT_CONSTEXPR decltype(R((*std::declval()).*(std::declval()))) + invoke(PMD&&, Pointer&&) SPROUT_NOEXCEPT_IF_EXPR(R((*std::declval()).*(std::declval()))); + + template + inline SPROUT_CONSTEXPR decltype(R((std::declval().*(std::declval()))(std::declval()...))) + invoke(T Base::*, Derived&&, Args&&...) SPROUT_NOEXCEPT_IF_EXPR(R((std::declval().*(std::declval()))(std::declval()...))); + + template + inline SPROUT_CONSTEXPR decltype(R(((*std::declval()).*(std::declval()))(std::declval()...))) + invoke(PMF&& pmf, Pointer&& ptr, Args&&... args) SPROUT_NOEXCEPT_IF_EXPR(R(((*std::declval()).*(std::declval()))(std::declval()...))); + } // namespace detail + + namespace detail { + template + struct invoke_result + : public sprout::detail::nil_base + {}; + template + struct invoke_result(), std::declval()...))>::type, F, Args...> + : public sprout::identity(), std::declval()...))> + {}; + } // namespace detail +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_DETAIL_INVOKE_HPP diff --git a/sprout/type_traits/invoke_result.hpp b/sprout/type_traits/invoke_result.hpp index 14310fcf..537c8876 100644 --- a/sprout/type_traits/invoke_result.hpp +++ b/sprout/type_traits/invoke_result.hpp @@ -9,7 +9,7 @@ #define SPROUT_TYPE_TRAITS_INVOKE_RESULT_HPP #include -#include +#include namespace sprout { // diff --git a/sprout/type_traits/is_invocable.hpp b/sprout/type_traits/is_invocable.hpp new file mode 100644 index 00000000..2a83b805 --- /dev/null +++ b/sprout/type_traits/is_invocable.hpp @@ -0,0 +1,43 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_IS_INVOCABLE_HPP +#define SPROUT_TYPE_TRAITS_IS_INVOCABLE_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // is_invocable + // + namespace detail { + template + struct is_invocable_impl + : public sprout::false_type + {}; + template + struct is_invocable_impl::type> + : public sprout::true_type + {}; + } // namespace detail + template + struct is_invocable + : public sprout::detail::is_invocable_impl< + sprout::invoke_result + >::type + {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_invocable_v = sprout::is_invocable::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_IS_INVOCABLE_HPP diff --git a/sprout/type_traits/is_invocable_r.hpp b/sprout/type_traits/is_invocable_r.hpp new file mode 100644 index 00000000..def53dba --- /dev/null +++ b/sprout/type_traits/is_invocable_r.hpp @@ -0,0 +1,46 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_IS_INVOCABLE_R_HPP +#define SPROUT_TYPE_TRAITS_IS_INVOCABLE_R_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // is_invocable_r + // + namespace detail { + template + struct is_invocable_r_impl + : public sprout::false_type + {}; + template + struct is_invocable_r_impl::type> + : public sprout::bool_constant< + std::is_void::value || std::is_convertible::value + > + {}; + } // namespace detail + template + struct is_invocable_r + : public sprout::detail::is_invocable_r_impl< + R, sprout::invoke_result + >::type + {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_invocable_r_v = sprout::is_invocable_r::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_IS_INVOCABLE_R_HPP diff --git a/sprout/type_traits/is_nothrow_invocable.hpp b/sprout/type_traits/is_nothrow_invocable.hpp new file mode 100644 index 00000000..7521f0df --- /dev/null +++ b/sprout/type_traits/is_nothrow_invocable.hpp @@ -0,0 +1,45 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_INVOCABLE_HPP +#define SPROUT_TYPE_TRAITS_IS_NOTHROW_INVOCABLE_HPP + +#include +#include +#include +#include + +namespace sprout { + // + // is_nothrow_invocable + // + namespace detail { + template + struct is_nothrow_invocable_impl + : public sprout::false_type + {}; + template + struct is_nothrow_invocable_impl + : public sprout::bool_constant< + SPROUT_NOEXCEPT_EXPR(sprout::detail::invoke(std::declval(), std::declval()...)) + > + {}; + } // namespace detail + template + struct is_nothrow_invocable + : public sprout::detail::is_nothrow_invocable_impl< + sprout::is_invocable::value, F, Args... + >::type + {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_nothrow_invocable_v = sprout::is_nothrow_invocable::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_INVOCABLE_HPP diff --git a/sprout/type_traits/is_nothrow_invocable_r.hpp b/sprout/type_traits/is_nothrow_invocable_r.hpp new file mode 100644 index 00000000..9a5ea95e --- /dev/null +++ b/sprout/type_traits/is_nothrow_invocable_r.hpp @@ -0,0 +1,47 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_INVOCABLE_R_HPP +#define SPROUT_TYPE_TRAITS_IS_NOTHROW_INVOCABLE_R_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + // + // is_nothrow_invocable_r + // + namespace detail { + template + struct is_nothrow_invocable_r_impl + : public sprout::false_type + {}; + template + struct is_nothrow_invocable_r_impl + : public sprout::bool_constant< + SPROUT_NOEXCEPT_EXPR(sprout::detail::invoke(std::declval(), std::declval()...)) + > + {}; + } // namespace detail + template + struct is_nothrow_invocable_r + : public sprout::detail::is_nothrow_invocable_r_impl< + sprout::is_invocable_r::value, R, F, Args... + >::type + {}; + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_nothrow_invocable_r_v = sprout::is_nothrow_invocable_r::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_IS_NOTHROW_INVOCABLE_R_HPP diff --git a/sprout/type_traits/relationship.hpp b/sprout/type_traits/relationship.hpp index e152bb86..3f0652fb 100644 --- a/sprout/type_traits/relationship.hpp +++ b/sprout/type_traits/relationship.hpp @@ -13,6 +13,10 @@ #include #include #include +#include +#include +#include +#include #include #include diff --git a/sprout/type_traits/result_of.hpp b/sprout/type_traits/result_of.hpp index 41bf7ab4..4cef0cde 100644 --- a/sprout/type_traits/result_of.hpp +++ b/sprout/type_traits/result_of.hpp @@ -8,42 +8,10 @@ #ifndef SPROUT_TYPE_TRAITS_RESULT_OF_HPP #define SPROUT_TYPE_TRAITS_RESULT_OF_HPP -#include #include -#include +#include namespace sprout { - namespace detail { - template - inline SPROUT_CONSTEXPR decltype(std::declval()(std::declval()...)) - invoke(F&&, Args&&...); - - template - inline SPROUT_CONSTEXPR decltype(std::declval().*(std::declval())) - invoke(T Base::*, Derived&&); - - template - inline SPROUT_CONSTEXPR decltype((*std::declval()).*(std::declval())) - invoke(PMD&&, Pointer&&); - - template - inline SPROUT_CONSTEXPR decltype((std::declval().*(std::declval()))(std::declval()...)) - invoke(T Base::*, Derived&&, Args&&...); - - template - inline SPROUT_CONSTEXPR decltype(((*std::declval()).*(std::declval()))(std::declval()...)) - invoke(PMF&& pmf, Pointer&& ptr, Args&&... args); - } // namespace detail - - namespace detail { - template - struct invoke_result {}; - template - struct invoke_result(), std::declval()...))), F, Args...> - : public sprout::identity(), std::declval()...))> - {}; - } // namespace detail - // // result_of // diff --git a/sprout/type_traits/void_t.hpp b/sprout/type_traits/void_t.hpp new file mode 100644 index 00000000..2c09b956 --- /dev/null +++ b/sprout/type_traits/void_t.hpp @@ -0,0 +1,14 @@ +/*============================================================================= + Copyright (c) 2011-2017 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_VOID_T_HPP +#define SPROUT_TYPE_TRAITS_VOID_T_HPP + +#include +#include + +#endif // #ifndef SPROUT_TYPE_TRAITS_VOID_T_HPP diff --git a/testspr/print.hpp b/testspr/print.hpp index a027aefe..5485219d 100644 --- a/testspr/print.hpp +++ b/testspr/print.hpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -181,4 +183,15 @@ namespace testspr { } } // namespace testspr +// +// TESTSPR_PRINT_EXPR +// +#if SPROUT_PP_VARIADICS +# define TESTSPR_PRINT_EXPR(...) \ + ::testspr::print_ln(SPROUT_PP_STRINGIZE((__VA_ARGS__)), " => ", __VA_ARGS__) +#else +# define TESTSPR_PRINT_EXPR(EXPR) \ + ::testspr::print_ln(SPROUT_PP_STRINGIZE((EXPR)), " => ", EXPR) +#endif + #endif // #ifndef TESTSPR_PRINT_HPP