Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix function target #1961

Merged
merged 2 commits into from
Jan 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions hpx/util/deferred_call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <hpx/util/invoke_fused.hpp>
#include <hpx/util/tuple.hpp>

#include <boost/static_assert.hpp>

#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -84,8 +82,9 @@ namespace hpx { namespace util
inline detail::deferred<F(Ts&&...)>
deferred_call(F&& f, Ts&&... vs)
{
BOOST_STATIC_ASSERT(
traits::detail::is_deferred_callable<F(Ts&&...)>::value);
static_assert(
traits::detail::is_deferred_callable<F(Ts&&...)>::value
, "F shall be Callable with decay_t<Ts> arguments");

return detail::deferred<F(Ts&&...)>(
std::forward<F>(f), std::forward<Ts>(vs)...);
Expand All @@ -96,8 +95,9 @@ namespace hpx { namespace util
inline typename std::decay<F>::type
deferred_call(F&& f)
{
BOOST_STATIC_ASSERT(
traits::detail::is_deferred_callable<F()>::value);
static_assert(
traits::detail::is_deferred_callable<F()>::value
, "F shall be Callable with no arguments");

return std::forward<F>(f);
}
Expand Down
18 changes: 8 additions & 10 deletions hpx/util/detail/basic_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,11 @@ namespace hpx { namespace util { namespace detail
template <typename T>
T* target() HPX_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(
(traits::is_callable<T(Ts...), R>::value)
, "T shall be Callable with the function signature"
);
typedef typename std::remove_cv<T>::type target_type;

typedef typename std::decay<T>::type target_type;
static_assert(
traits::is_callable<target_type&(Ts...), R>::value
, "T shall be Callable with the function signature");

VTablePtr const* f_vptr = get_table_ptr<target_type>();
if (vptr != f_vptr || empty())
Expand All @@ -237,12 +236,11 @@ namespace hpx { namespace util { namespace detail
template <typename T>
T const* target() const HPX_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG(
(traits::is_callable<T(Ts...), R>::value)
, "T shall be Callable with the function signature"
);
typedef typename std::remove_cv<T>::type target_type;

typedef typename std::decay<T>::type target_type;
static_assert(
traits::is_callable<target_type&(Ts...), R>::value
, "T shall be Callable with the function signature");

VTablePtr const* f_vptr = get_table_ptr<target_type>();
if (vptr != f_vptr || empty())
Expand Down
1 change: 1 addition & 0 deletions tests/unit/util/function/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(tests
function_arith
function_args
function_ref
function_target
function_test
nothrow_swap
stateless_test
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/util/function/function_target.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2016 Agustin Berge
//
// 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)

#include <hpx/hpx.hpp>
#include <hpx/util/function.hpp>
#include <hpx/util/lightweight_test.hpp>

#include <typeinfo>

struct foo
{
int operator()() { return 0; }
void operator()() const {}
};

int main()
{
{
hpx::util::function<int()> fun = foo();

HPX_TEST(fun.target_type() == typeid(foo));
HPX_TEST(fun.target<foo>() != 0);
}

{
hpx::util::function<int()> fun = foo();

HPX_TEST(fun.target_type() == typeid(foo const));
HPX_TEST(fun.target<foo const>() != 0);
}

return hpx::util::report_errors();
}