File tree Expand file tree Collapse file tree 5 files changed +37
-7
lines changed Expand file tree Collapse file tree 5 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -82,18 +82,18 @@ class pointer_functor<T_return(T_args...)>
82
82
public:
83
83
84
84
// / Constructs an invalid functor.
85
- pointer_functor () = default ;
85
+ constexpr pointer_functor () = default;
86
86
87
87
/* * Constructs a pointer_functor2 object that wraps an existing function.
88
88
* @param func Pointer to function that will be invoked from operator()().
89
89
*/
90
- explicit pointer_functor (function_type func) : func_ptr_(func) {}
90
+ constexpr explicit pointer_functor (function_type func) : func_ptr_(func) {}
91
91
92
92
/* * Execute the wrapped function.
93
93
* @param a Arguments to be passed on to the function.
94
94
* @return The return value of the function invocation.
95
95
*/
96
- T_return operator ()(type_trait_take_t <T_args>... a) const {
96
+ constexpr T_return operator ()(type_trait_take_t <T_args>... a) const {
97
97
return std::invoke (func_ptr_, a...);
98
98
}
99
99
};
@@ -105,7 +105,7 @@ class pointer_functor<T_return(T_args...)>
105
105
* @ingroup ptr_fun
106
106
*/
107
107
template <typename T_return, typename ... T_args>
108
- inline decltype (auto ) ptr_fun(T_return (*func)(T_args...))
108
+ inline constexpr decltype (auto ) ptr_fun(T_return (*func)(T_args...))
109
109
{
110
110
return pointer_functor<T_return (T_args...)>(func);
111
111
}
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ namespace internal
48
48
* (argument-dependent lookup).
49
49
*/
50
50
template <typename T_out, typename T_in>
51
- inline T_out function_pointer_cast (T_in in)
51
+ inline constexpr T_out function_pointer_cast (T_in in)
52
52
{
53
53
// The double reinterpret_cast suppresses a warning from gcc8 with the
54
54
// -Wcast-function-type option.
@@ -78,13 +78,13 @@ struct typed_slot_rep : public slot_rep
78
78
* The notification callback is registered using visit_each().
79
79
* @param functor The functor contained by the new slot_rep object.
80
80
*/
81
- inline explicit typed_slot_rep (const T_functor& functor)
81
+ inline constexpr explicit typed_slot_rep (const T_functor& functor)
82
82
: slot_rep(nullptr ), functor_(std::make_unique<adaptor_type>(functor))
83
83
{
84
84
sigc::visit_each_trackable (slot_do_bind (this ), *functor_);
85
85
}
86
86
87
- inline typed_slot_rep (const typed_slot_rep& src)
87
+ inline constexpr typed_slot_rep (const typed_slot_rep& src)
88
88
: slot_rep(src.call_), functor_(std::make_unique<adaptor_type>(*src.functor_))
89
89
{
90
90
sigc::visit_each_trackable (slot_do_bind (this ), *functor_);
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ set (TEST_SOURCE_FILES
26
26
test_bind_return.cc
27
27
test_compose.cc
28
28
test_connection.cc
29
+ test_constexpr.cc
29
30
test_copy_invalid_slot.cc
30
31
test_cpp11_lambda.cc
31
32
test_custom.cc
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ check_PROGRAMS = \
33
33
test_bind_return \
34
34
test_compose \
35
35
test_connection \
36
+ test_constexpr \
36
37
test_copy_invalid_slot \
37
38
test_cpp11_lambda \
38
39
test_custom \
@@ -77,6 +78,7 @@ test_bind_refptr_SOURCES = test_bind_refptr.cc $(sigc_test_util)
77
78
test_bind_return_SOURCES = test_bind_return.cc $(sigc_test_util )
78
79
test_compose_SOURCES = test_compose.cc $(sigc_test_util )
79
80
test_connection_SOURCES = test_connection.cc $(sigc_test_util )
81
+ test_constexpr_SOURCES = test_constexpr.cc $(sigc_test_util )
80
82
test_copy_invalid_slot_SOURCES = test_copy_invalid_slot.cc $(sigc_test_util )
81
83
test_cpp11_lambda_SOURCES = test_cpp11_lambda.cc $(sigc_test_util )
82
84
test_custom_SOURCES = test_custom.cc $(sigc_test_util )
Original file line number Diff line number Diff line change
1
+ /* Copyright 2002 - 2016, The libsigc++ Development Team
2
+ * Assigned to public domain. Use as you wish without restriction.
3
+ */
4
+
5
+ #include " testutilities.h"
6
+ #include < sigc++/sigc++.h>
7
+
8
+ namespace {
9
+
10
+ constexpr
11
+ int foo (int a, int b) {
12
+ return a + b;
13
+ }
14
+
15
+ } // end anonymous namespace
16
+
17
+ int
18
+ main ()
19
+ {
20
+ constexpr auto slot = sigc::ptr_fun (&foo);
21
+ constexpr auto result = slot (1 , 2 );
22
+ if (result != 3 ) {
23
+ return EXIT_FAILURE;
24
+ }
25
+
26
+ EXIT_SUCCESS;
27
+ }
You can’t perform that action at this time.
0 commit comments