From d2669d2a78b804b53243a587a81c7d8c67ada50e Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 5 Feb 2019 09:52:35 -0800 Subject: [PATCH] is_invocable is in its own header file --- .../boost/beast/core/detail/is_invocable.hpp | 58 ++++++++++++++++++ include/boost/beast/core/detail/read.hpp | 1 + .../boost/beast/core/detail/type_traits.hpp | 37 +----------- include/boost/beast/core/type_traits.hpp | 1 + .../beast/websocket/detail/type_traits.hpp | 2 +- test/beast/core/CMakeLists.txt | 1 + test/beast/core/Jamfile | 1 + test/beast/core/_detail_is_invocable.cpp | 60 +++++++++++++++++++ test/beast/core/buffer_size.cpp | 2 +- test/beast/core/type_traits.cpp | 46 +------------- 10 files changed, 126 insertions(+), 83 deletions(-) create mode 100644 include/boost/beast/core/detail/is_invocable.hpp create mode 100644 test/beast/core/_detail_is_invocable.cpp diff --git a/include/boost/beast/core/detail/is_invocable.hpp b/include/boost/beast/core/detail/is_invocable.hpp new file mode 100644 index 00000000..d64c596d --- /dev/null +++ b/include/boost/beast/core/detail/is_invocable.hpp @@ -0,0 +1,58 @@ +// +// Copyright (c) 2019 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// 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) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP +#define BOOST_BEAST_DETAIL_IS_INVOCABLE_HPP + +#include +#include + +namespace boost { +namespace beast { +namespace detail { + +template +auto +is_invocable_test(C&& c, int, A&& ...a) + -> decltype(std::is_convertible< + decltype(c(std::forward(a)...)), R>::value || + std::is_same::value, + std::true_type()); + +template +std::false_type +is_invocable_test(C&& c, long, A&& ...a); + +/** Metafunction returns `true` if F callable as R(A...) + + Example: + + @code + is_invocable::value + @endcode +*/ +/** @{ */ +template +struct is_invocable : std::false_type +{ +}; + +template +struct is_invocable + : decltype(is_invocable_test( + std::declval(), 1, std::declval()...)) +{ +}; +/** @} */ + +} // detail +} // beast +} // boost + +#endif diff --git a/include/boost/beast/core/detail/read.hpp b/include/boost/beast/core/detail/read.hpp index 2f425030..437a500f 100644 --- a/include/boost/beast/core/detail/read.hpp +++ b/include/boost/beast/core/detail/read.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/include/boost/beast/core/detail/type_traits.hpp b/include/boost/beast/core/detail/type_traits.hpp index fbe4cf0d..948b4993 100644 --- a/include/boost/beast/core/detail/type_traits.hpp +++ b/include/boost/beast/core/detail/type_traits.hpp @@ -11,6 +11,7 @@ #define BOOST_BEAST_DETAIL_TYPE_TRAITS_HPP #include +#include #include #include #include @@ -102,42 +103,6 @@ accept_rv(T){} //------------------------------------------------------------------------------ -template -auto -is_invocable_test(C&& c, int, A&& ...a) - -> decltype(std::is_convertible< - decltype(c(std::forward(a)...)), R>::value || - std::is_same::value, - std::true_type()); - -template -std::false_type -is_invocable_test(C&& c, long, A&& ...a); - -/** Metafunction returns `true` if F callable as R(A...) - - Example: - - @code - is_invocable - @endcode -*/ -/** @{ */ -template -struct is_invocable : std::false_type -{ -}; - -template -struct is_invocable - : decltype(is_invocable_test( - std::declval(), 1, std::declval()...)) -{ -}; -/** @} */ - -//------------------------------------------------------------------------------ - // for span template struct is_contiguous_container: std::false_type {}; diff --git a/include/boost/beast/core/type_traits.hpp b/include/boost/beast/core/type_traits.hpp index 5903ef78..a84d2879 100644 --- a/include/boost/beast/core/type_traits.hpp +++ b/include/boost/beast/core/type_traits.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include diff --git a/include/boost/beast/websocket/detail/type_traits.hpp b/include/boost/beast/websocket/detail/type_traits.hpp index 6913174f..2233966b 100644 --- a/include/boost/beast/websocket/detail/type_traits.hpp +++ b/include/boost/beast/websocket/detail/type_traits.hpp @@ -11,7 +11,7 @@ #define BOOST_BEAST_WEBSOCKET_DETAIL_TYPE_TRAITS_HPP #include -#include +#include namespace boost { namespace beast { diff --git a/test/beast/core/CMakeLists.txt b/test/beast/core/CMakeLists.txt index eafdd189..d52f233b 100644 --- a/test/beast/core/CMakeLists.txt +++ b/test/beast/core/CMakeLists.txt @@ -23,6 +23,7 @@ add_executable (tests-beast-core _detail_base64.cpp _detail_buffer.cpp _detail_clamp.cpp + _detail_is_invocable.cpp _detail_read.cpp _detail_sha1.cpp _detail_tuple.cpp diff --git a/test/beast/core/Jamfile b/test/beast/core/Jamfile index 89a4fefe..c5287237 100644 --- a/test/beast/core/Jamfile +++ b/test/beast/core/Jamfile @@ -11,6 +11,7 @@ local SOURCES = _detail_base64.cpp _detail_buffer.cpp _detail_clamp.cpp + _detail_is_invocable.cpp _detail_read.cpp _detail_sha1.cpp _detail_tuple.cpp diff --git a/test/beast/core/_detail_is_invocable.cpp b/test/beast/core/_detail_is_invocable.cpp new file mode 100644 index 00000000..4bcf706c --- /dev/null +++ b/test/beast/core/_detail_is_invocable.cpp @@ -0,0 +1,60 @@ +// +// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// 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) +// +// Official repository: https://github.com/boostorg/beast +// + +#include +#include +#include + +namespace boost { +namespace beast { +namespace detail { + +namespace { + +// +// is_invocable +// + +struct is_invocable_udt1 +{ + void operator()(int) const; +}; + +struct is_invocable_udt2 +{ + int operator()(int) const; +}; + +struct is_invocable_udt3 +{ + int operator()(int); +}; + +struct is_invocable_udt4 +{ + void operator()(std::unique_ptr); +}; + +#ifndef __INTELLISENSE__ +// VFALCO Fails to compile with Intellisense +BOOST_STATIC_ASSERT(is_invocable::value); +BOOST_STATIC_ASSERT(is_invocable::value); +BOOST_STATIC_ASSERT(is_invocable::value); +BOOST_STATIC_ASSERT(! is_invocable::value); +BOOST_STATIC_ASSERT(! is_invocable::value); +BOOST_STATIC_ASSERT(! is_invocable::value); +BOOST_STATIC_ASSERT(! is_invocable::value); +BOOST_STATIC_ASSERT(is_invocable)>::value); +#endif + +} // (anonymous) + +} // detail +} // beast +} // boost diff --git a/test/beast/core/buffer_size.cpp b/test/beast/core/buffer_size.cpp index 812b59eb..2b24ed04 100644 --- a/test/beast/core/buffer_size.cpp +++ b/test/beast/core/buffer_size.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include namespace boost { namespace beast { diff --git a/test/beast/core/type_traits.cpp b/test/beast/core/type_traits.cpp index 9671afcc..23fe51c4 100644 --- a/test/beast/core/type_traits.cpp +++ b/test/beast/core/type_traits.cpp @@ -19,50 +19,6 @@ namespace boost { namespace beast { -namespace detail { - -namespace { - -// -// is_invocable -// - -struct is_invocable_udt1 -{ - void operator()(int) const; -}; - -struct is_invocable_udt2 -{ - int operator()(int) const; -}; - -struct is_invocable_udt3 -{ - int operator()(int); -}; - -struct is_invocable_udt4 -{ - void operator()(std::unique_ptr); -}; - -#ifndef __INTELLISENSE__ -// VFALCO Fails to compile with Intellisense -BOOST_STATIC_ASSERT(is_invocable::value); -BOOST_STATIC_ASSERT(is_invocable::value); -BOOST_STATIC_ASSERT(is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -BOOST_STATIC_ASSERT(is_invocable)>::value); -#endif - -} // (anonymous) - -} // detail - // // handler concepts // @@ -71,7 +27,7 @@ namespace { struct H { - void operator()(int); + void operator()(int){} }; } // anonymous