• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/libs/core/functional/include/hpx/functional/function.hpp
1
//  Copyright (c) 2011 Thomas Heller
2
//  Copyright (c) 2013-2025 Hartmut Kaiser
3
//  Copyright (c) 2014-2015 Agustin Berge
4
//
5
//  SPDX-License-Identifier: BSL-1.0
6
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
7
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8

9
/// \file function.hpp
10
/// \page hpx::function
11
/// \headerfile hpx/functional.hpp
12

13
#pragma once
14

15
#include <hpx/config.hpp>
16
#include <hpx/functional/detail/basic_function.hpp>
17
#include <hpx/functional/detail/function_registration.hpp>
18
#include <hpx/functional/traits/get_function_address.hpp>
19
#include <hpx/functional/traits/get_function_annotation.hpp>
20
#include <hpx/modules/tag_invoke.hpp>
21

22
#include <cstddef>
23
#include <type_traits>
24
#include <utility>
25

26
namespace hpx {
27

28
    ///////////////////////////////////////////////////////////////////////////
29
    /// Class template hpx::function is a general-purpose polymorphic function
30
    /// wrapper. Instances of hpx::function can store, copy, and invoke any
31
    /// CopyConstructible Callable target -- functions, lambda expressions, bind
32
    /// expressions, or other function objects, as well as pointers to member
33
    /// functions and pointers to data members. The stored callable object is
34
    /// called the target of hpx::function. If an hpx::function contains no
35
    /// target, it is called empty. Invoking the target of an empty
36
    /// hpx::function results in \a hpx#error#bad_function_call exception being
37
    /// thrown. hpx::function satisfies the requirements of CopyConstructible
38
    /// and CopyAssignable.
39
    HPX_CXX_EXPORT template <typename Sig, bool Serializable = false>
40
    class function;
41

42
    HPX_CXX_EXPORT template <typename R, typename... Ts, bool Serializable>
43
    class function<R(Ts...), Serializable>
44
      : public util::detail::basic_function<R(Ts...), true, Serializable>
45
    {
46
        using base_type =
47
            util::detail::basic_function<R(Ts...), true, Serializable>;
48

49
    public:
50
        using result_type = R;
×
51

52
        constexpr function(std::nullptr_t = nullptr) noexcept {}    //-V832
252,313✔
53

54
        function(function const&) = default;
64✔
55
        function(function&&) noexcept = default;
×
56
        function& operator=(function const&) = default;
57
        function& operator=(function&&) noexcept = default;
42,820✔
58

59
        ~function() = default;
60

61
        // the split SFINAE prevents MSVC from eagerly instantiating things
62
        template <typename F, typename FD = std::decay_t<F>,
63
            typename Enable1 = std::enable_if_t<!std::is_same_v<FD, function>>,
64
            typename Enable2 =
1,543✔
65
                std::enable_if_t<is_invocable_r_v<R, FD&, Ts...>>>
1,551✔
66
        function(F&& f)
6,680✔
67
        {
1,543✔
68
            assign(HPX_FORWARD(F, f));
69
        }
70

71
        // the split SFINAE prevents MSVC from eagerly instantiating things
72
        template <typename F, typename FD = std::decay_t<F>,
73
            typename Enable1 = std::enable_if_t<!std::is_same_v<FD, function>>,
74
            typename Enable2 =
75
                std::enable_if_t<is_invocable_r_v<R, FD&, Ts...>>>
76
        function& operator=(F&& f)
32✔
77
        {
×
78
            assign(HPX_FORWARD(F, f));
79
            return *this;
80
        }
81

82
        using base_type::operator();
83
        using base_type::assign;
84
        using base_type::empty;
85
        using base_type::reset;
86
        using base_type::target;
87
    };
88

89
    namespace distributed {
90

91
        // serializable function is equivalent to hpx::distributed::function
92
        HPX_CXX_EXPORT template <typename Sig>
93
        using function = hpx::function<Sig, true>;
94
    }    // namespace distributed
95
}    // namespace hpx
96

97
#if defined(HPX_HAVE_THREAD_DESCRIPTION)
98
///////////////////////////////////////////////////////////////////////////////
99
namespace hpx::traits {
100

101
    HPX_CXX_EXPORT template <typename Sig, bool Serializable>
102
    struct get_function_address<hpx::function<Sig, Serializable>>
103
    {
104
        [[nodiscard]] static constexpr std::size_t call(
105
            hpx::function<Sig, Serializable> const& f) noexcept
106
        {
107
            return f.get_function_address();
108
        }
109
    };
110

111
    HPX_CXX_EXPORT template <typename Sig, bool Serializable>
112
    struct get_function_annotation<hpx::function<Sig, Serializable>>
113
    {
114
        [[nodiscard]] static constexpr char const* call(
115
            hpx::function<Sig, Serializable> const& f) noexcept
116
        {
117
            return f.get_function_annotation();
118
        }
119
    };
120

121
#if HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
122
    HPX_CXX_EXPORT template <typename Sig, bool Serializable>
123
    struct get_function_annotation_itt<hpx::function<Sig, Serializable>>
124
    {
125
        [[nodiscard]] static util::itt::string_handle call(
126
            hpx::function<Sig, Serializable> const& f) noexcept
127
        {
128
            return f.get_function_annotation_itt();
129
        }
130
    };
131
#endif
132
}    // namespace hpx::traits
133
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc