mirror of
https://github.com/boostorg/beast.git
synced 2025-08-02 14:24:31 +02:00
is_invocable is in its own header file
This commit is contained in:
58
include/boost/beast/core/detail/is_invocable.hpp
Normal file
58
include/boost/beast/core/detail/is_invocable.hpp
Normal file
@@ -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 <type_traits>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace beast {
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<class R, class C, class ...A>
|
||||||
|
auto
|
||||||
|
is_invocable_test(C&& c, int, A&& ...a)
|
||||||
|
-> decltype(std::is_convertible<
|
||||||
|
decltype(c(std::forward<A>(a)...)), R>::value ||
|
||||||
|
std::is_same<R, void>::value,
|
||||||
|
std::true_type());
|
||||||
|
|
||||||
|
template<class R, class C, class ...A>
|
||||||
|
std::false_type
|
||||||
|
is_invocable_test(C&& c, long, A&& ...a);
|
||||||
|
|
||||||
|
/** Metafunction returns `true` if F callable as R(A...)
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
@code
|
||||||
|
is_invocable<T, void(std::string)>::value
|
||||||
|
@endcode
|
||||||
|
*/
|
||||||
|
/** @{ */
|
||||||
|
template<class C, class F>
|
||||||
|
struct is_invocable : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class C, class R, class ...A>
|
||||||
|
struct is_invocable<C, R(A...)>
|
||||||
|
: decltype(is_invocable_test<R>(
|
||||||
|
std::declval<C>(), 1, std::declval<A>()...))
|
||||||
|
{
|
||||||
|
};
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
} // beast
|
||||||
|
} // boost
|
||||||
|
|
||||||
|
#endif
|
@@ -13,6 +13,7 @@
|
|||||||
#include <boost/beast/core/detail/config.hpp>
|
#include <boost/beast/core/detail/config.hpp>
|
||||||
#include <boost/beast/core/error.hpp>
|
#include <boost/beast/core/error.hpp>
|
||||||
#include <boost/beast/core/stream_traits.hpp>
|
#include <boost/beast/core/stream_traits.hpp>
|
||||||
|
#include <boost/beast/core/detail/is_invocable.hpp>
|
||||||
#include <boost/asio/async_result.hpp>
|
#include <boost/asio/async_result.hpp>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
#define BOOST_BEAST_DETAIL_TYPE_TRAITS_HPP
|
#define BOOST_BEAST_DETAIL_TYPE_TRAITS_HPP
|
||||||
|
|
||||||
#include <boost/beast/core/error.hpp>
|
#include <boost/beast/core/error.hpp>
|
||||||
|
#include <boost/beast/core/detail/is_invocable.hpp>
|
||||||
#include <boost/asio/buffer.hpp>
|
#include <boost/asio/buffer.hpp>
|
||||||
#include <boost/mp11/function.hpp>
|
#include <boost/mp11/function.hpp>
|
||||||
#include <boost/type_traits/make_void.hpp>
|
#include <boost/type_traits/make_void.hpp>
|
||||||
@@ -102,42 +103,6 @@ accept_rv(T){}
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
template<class R, class C, class ...A>
|
|
||||||
auto
|
|
||||||
is_invocable_test(C&& c, int, A&& ...a)
|
|
||||||
-> decltype(std::is_convertible<
|
|
||||||
decltype(c(std::forward<A>(a)...)), R>::value ||
|
|
||||||
std::is_same<R, void>::value,
|
|
||||||
std::true_type());
|
|
||||||
|
|
||||||
template<class R, class C, class ...A>
|
|
||||||
std::false_type
|
|
||||||
is_invocable_test(C&& c, long, A&& ...a);
|
|
||||||
|
|
||||||
/** Metafunction returns `true` if F callable as R(A...)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
@code
|
|
||||||
is_invocable<T, void(std::string)>
|
|
||||||
@endcode
|
|
||||||
*/
|
|
||||||
/** @{ */
|
|
||||||
template<class C, class F>
|
|
||||||
struct is_invocable : std::false_type
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class C, class R, class ...A>
|
|
||||||
struct is_invocable<C, R(A...)>
|
|
||||||
: decltype(is_invocable_test<R>(
|
|
||||||
std::declval<C>(), 1, std::declval<A>()...))
|
|
||||||
{
|
|
||||||
};
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// for span
|
// for span
|
||||||
template<class T, class E, class = void>
|
template<class T, class E, class = void>
|
||||||
struct is_contiguous_container: std::false_type {};
|
struct is_contiguous_container: std::false_type {};
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <boost/beast/core/detail/config.hpp>
|
#include <boost/beast/core/detail/config.hpp>
|
||||||
#include <boost/beast/core/file_base.hpp>
|
#include <boost/beast/core/file_base.hpp>
|
||||||
|
#include <boost/beast/core/detail/is_invocable.hpp>
|
||||||
#include <boost/beast/core/detail/type_traits.hpp>
|
#include <boost/beast/core/detail/type_traits.hpp>
|
||||||
#include <boost/asio/buffer.hpp>
|
#include <boost/asio/buffer.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
#define BOOST_BEAST_WEBSOCKET_DETAIL_TYPE_TRAITS_HPP
|
#define BOOST_BEAST_WEBSOCKET_DETAIL_TYPE_TRAITS_HPP
|
||||||
|
|
||||||
#include <boost/beast/websocket/rfc6455.hpp>
|
#include <boost/beast/websocket/rfc6455.hpp>
|
||||||
#include <boost/beast/core/detail/type_traits.hpp>
|
#include <boost/beast/core/detail/is_invocable.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
@@ -23,6 +23,7 @@ add_executable (tests-beast-core
|
|||||||
_detail_base64.cpp
|
_detail_base64.cpp
|
||||||
_detail_buffer.cpp
|
_detail_buffer.cpp
|
||||||
_detail_clamp.cpp
|
_detail_clamp.cpp
|
||||||
|
_detail_is_invocable.cpp
|
||||||
_detail_read.cpp
|
_detail_read.cpp
|
||||||
_detail_sha1.cpp
|
_detail_sha1.cpp
|
||||||
_detail_tuple.cpp
|
_detail_tuple.cpp
|
||||||
|
@@ -11,6 +11,7 @@ local SOURCES =
|
|||||||
_detail_base64.cpp
|
_detail_base64.cpp
|
||||||
_detail_buffer.cpp
|
_detail_buffer.cpp
|
||||||
_detail_clamp.cpp
|
_detail_clamp.cpp
|
||||||
|
_detail_is_invocable.cpp
|
||||||
_detail_read.cpp
|
_detail_read.cpp
|
||||||
_detail_sha1.cpp
|
_detail_sha1.cpp
|
||||||
_detail_tuple.cpp
|
_detail_tuple.cpp
|
||||||
|
60
test/beast/core/_detail_is_invocable.cpp
Normal file
60
test/beast/core/_detail_is_invocable.cpp
Normal file
@@ -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 <boost/beast/core/detail/config.hpp>
|
||||||
|
#include <boost/beast/core/detail/is_invocable.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
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<int>);
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef __INTELLISENSE__
|
||||||
|
// VFALCO Fails to compile with Intellisense
|
||||||
|
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt1, void(int)>::value);
|
||||||
|
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt2, int(int)>::value);
|
||||||
|
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt3, int(int)>::value);
|
||||||
|
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt1, void(void)>::value);
|
||||||
|
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt2, int(void)>::value);
|
||||||
|
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt2, void(void)>::value);
|
||||||
|
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt3 const, int(int)>::value);
|
||||||
|
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt4, void(std::unique_ptr<int>)>::value);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // (anonymous)
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
} // beast
|
||||||
|
} // boost
|
@@ -11,7 +11,7 @@
|
|||||||
#include <boost/beast/core/buffer_size.hpp>
|
#include <boost/beast/core/buffer_size.hpp>
|
||||||
|
|
||||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||||
#include <boost/beast/core/detail/type_traits.hpp>
|
#include <boost/beast/core/detail/is_invocable.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
@@ -19,50 +19,6 @@
|
|||||||
namespace boost {
|
namespace boost {
|
||||||
namespace beast {
|
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<int>);
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifndef __INTELLISENSE__
|
|
||||||
// VFALCO Fails to compile with Intellisense
|
|
||||||
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt1, void(int)>::value);
|
|
||||||
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt2, int(int)>::value);
|
|
||||||
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt3, int(int)>::value);
|
|
||||||
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt1, void(void)>::value);
|
|
||||||
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt2, int(void)>::value);
|
|
||||||
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt2, void(void)>::value);
|
|
||||||
BOOST_STATIC_ASSERT(! is_invocable<is_invocable_udt3 const, int(int)>::value);
|
|
||||||
BOOST_STATIC_ASSERT(is_invocable<is_invocable_udt4, void(std::unique_ptr<int>)>::value);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // (anonymous)
|
|
||||||
|
|
||||||
} // detail
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// handler concepts
|
// handler concepts
|
||||||
//
|
//
|
||||||
@@ -71,7 +27,7 @@ namespace {
|
|||||||
|
|
||||||
struct H
|
struct H
|
||||||
{
|
{
|
||||||
void operator()(int);
|
void operator()(int){}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // anonymous
|
} // anonymous
|
||||||
|
Reference in New Issue
Block a user