Skip to content

Commit e3d8fcb

Browse files
committed
Support const callables
Fixes #2
1 parent 3cd744f commit e3d8fcb

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
1111
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
1212
${CMAKE_CURRENT_SOURCE_DIR}/tests/constructors.cpp
1313
${CMAKE_CURRENT_SOURCE_DIR}/tests/call.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/tests/issues.cpp
1415
${CMAKE_CURRENT_SOURCE_DIR}/tests/assignment.cpp)
1516

1617
add_executable(tests ${TEST_SOURCES})

function_ref.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define TL_FUNCTION_REF_HPP
1616

1717
#define TL_FUNCTION_REF_VERSION_MAJOR 0
18-
#define TL_FUNCTION_REF_VERSION_MINOR 1
18+
#define TL_FUNCTION_REF_VERSION_MINOR 2
1919

2020
#if (defined(_MSC_VER) && _MSC_VER == 1900)
2121
/// \exclude
@@ -151,7 +151,7 @@ template <class R, class... Args> class function_ref<R(Args...)> {
151151
!std::is_same<detail::decay_t<F>, function_ref>::value &&
152152
detail::is_invocable_r<R, F &&, Args...>::value> * = nullptr>
153153
TL_FUNCTION_REF_11_CONSTEXPR function_ref(F &&f) noexcept
154-
: obj_(reinterpret_cast<void *>(std::addressof(f))) {
154+
: obj_(const_cast<void*>(reinterpret_cast<const void *>(std::addressof(f)))) {
155155
callback_ = [](void *obj, Args... args) {
156156
return detail::invoke(
157157
*reinterpret_cast<typename std::add_pointer<F>::type>(obj),

tests/issues.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "catch.hpp"
2+
#include "function_ref.hpp"
3+
4+
TEST_CASE("Issue #2") {
5+
const auto lam = [](int x) {};
6+
tl::function_ref<void(int)> ref = lam;
7+
}

0 commit comments

Comments
 (0)