Rename to detail::is_invocable

Fix #323
This commit is contained in:
Vinnie Falco
2017-04-27 17:33:11 -07:00
parent 512ab5ba7d
commit 4b19600dd2
9 changed files with 99 additions and 117 deletions

View File

@ -1,6 +1,7 @@
1.0.0-b37
* CMake hide command lines in .vcxproj Output windows"
* Rename to detail::is_invocable
WebSocket:

View File

@ -1,54 +0,0 @@
//
// Copyright (c) 2013-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)
//
#ifndef BEAST_DETAIL_IS_CALL_POSSIBLE_HPP
#define BEAST_DETAIL_IS_CALL_POSSIBLE_HPP
#include <type_traits>
namespace beast {
namespace detail {
template<class R, class C, class ...A>
auto
is_call_possible_test(C&& c, int, A&& ...a)
-> decltype(std::is_convertible<
decltype(c(a...)), R>::value ||
std::is_same<R, void>::value,
std::true_type());
template<class R, class C, class ...A>
std::false_type
is_call_possible_test(C&& c, long, A&& ...a);
/** Metafunction returns `true` if F callable as R(A...)
Example:
@code
is_call_possible<T, void(std::string)>
@endcode
*/
/** @{ */
template<class C, class F>
struct is_call_possible
: std::false_type
{
};
template<class C, class R, class ...A>
struct is_call_possible<C, R(A...)>
: decltype(is_call_possible_test<R>(
std::declval<C>(), 1, std::declval<A>()...))
{
};
/** @} */
} // detail
} // beast
#endif

View File

@ -92,6 +92,41 @@ make_exception(char const* reason, char const* file, int line)
n + ":" + std::to_string(line) + ")"};
}
template<class R, class C, class ...A>
auto
is_invocable_test(C&& c, int, A&& ...a)
-> decltype(std::is_convertible<
decltype(c(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>()...))
{
};
/** @} */
} // detail
} // beast

View File

@ -9,7 +9,7 @@
#define BEAST_HANDLER_CONCEPTS_HPP
#include <beast/config.hpp>
#include <beast/core/detail/is_call_possible.hpp>
#include <beast/core/detail/type_traits.hpp>
#include <type_traits>
namespace beast {
@ -21,7 +21,7 @@ using is_CompletionHandler = std::integral_constant<bool, ...>;
#else
using is_CompletionHandler = std::integral_constant<bool,
std::is_copy_constructible<typename std::decay<T>::type>::value &&
detail::is_call_possible<T, Signature>::value>;
detail::is_invocable<T, Signature>::value>;
#endif
} // beast

View File

@ -9,7 +9,7 @@
#define BEAST_WEBSOCKET_DETAIL_TYPE_TRAITS_HPP
#include <beast/websocket/rfc6455.hpp>
#include <beast/core/detail/is_call_possible.hpp>
#include <beast/core/detail/type_traits.hpp>
namespace beast {
namespace websocket {
@ -17,12 +17,12 @@ namespace detail {
template<class F>
using is_RequestDecorator =
typename beast::detail::is_call_possible<F,
typename beast::detail::is_invocable<F,
void(request_type&)>::type;
template<class F>
using is_ResponseDecorator =
typename beast::detail::is_call_possible<F,
typename beast::detail::is_invocable<F,
void(response_type&)>::type;
} // detail

View File

@ -41,8 +41,8 @@ unit-test core-tests :
core/base64.cpp
core/empty_base_optimization.cpp
core/get_lowest_layer.cpp
core/is_call_possible.cpp
core/sha1.cpp
core/type_traits.cpp
;
unit-test http-tests :

View File

@ -34,8 +34,8 @@ add_executable (core-tests
base64.cpp
empty_base_optimization.cpp
get_lowest_layer.cpp
is_call_possible.cpp
sha1.cpp
type_traits.cpp
)
if (NOT WIN32)

View File

@ -1,56 +0,0 @@
//
// Copyright (c) 2013-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)
//
// Test that header file is self-contained.
#include <beast/core/detail/is_call_possible.hpp>
namespace beast {
namespace detail {
namespace {
struct is_call_possible_udt1
{
void operator()(int) const;
};
struct is_call_possible_udt2
{
int operator()(int) const;
};
struct is_call_possible_udt3
{
int operator()(int);
};
#ifndef __INTELLISENSE__
// VFALCO Fails to compile with Intellisense
static_assert(is_call_possible<
is_call_possible_udt1, void(int)>::value, "");
static_assert(! is_call_possible<
is_call_possible_udt1, void(void)>::value, "");
static_assert(is_call_possible<
is_call_possible_udt2, int(int)>::value, "");
static_assert(! is_call_possible<
is_call_possible_udt2, int(void)>::value, "");
static_assert(! is_call_possible<
is_call_possible_udt2, void(void)>::value, "");
static_assert(is_call_possible<
is_call_possible_udt3, int(int)>::value, "");
static_assert(! is_call_possible<
is_call_possible_udt3 const, int(int)>::value, "");
#endif
}
} // detail
} // beast

56
test/core/type_traits.cpp Normal file
View File

@ -0,0 +1,56 @@
//
// Copyright (c) 2013-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)
//
// Test that header file is self-contained.
#include <beast/core/detail/type_traits.hpp>
namespace beast {
namespace detail {
namespace {
struct is_invocable_udt1
{
void operator()(int) const;
};
struct is_invocable_udt2
{
int operator()(int) const;
};
struct is_invocable_udt3
{
int operator()(int);
};
#ifndef __INTELLISENSE__
// VFALCO Fails to compile with Intellisense
static_assert(is_invocable<
is_invocable_udt1, void(int)>::value, "");
static_assert(! is_invocable<
is_invocable_udt1, void(void)>::value, "");
static_assert(is_invocable<
is_invocable_udt2, int(int)>::value, "");
static_assert(! is_invocable<
is_invocable_udt2, int(void)>::value, "");
static_assert(! is_invocable<
is_invocable_udt2, void(void)>::value, "");
static_assert(is_invocable<
is_invocable_udt3, int(int)>::value, "");
static_assert(! is_invocable<
is_invocable_udt3 const, int(int)>::value, "");
#endif
}
} // detail
} // beast