Skip to content

Commit b74a336

Browse files
committed
Force-inline UFCS lambdas, closes #185
1 parent 9ddc250 commit b74a336

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

include/cpp2util.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,14 @@ class out {
501501
//
502502
//-----------------------------------------------------------------------
503503
//
504+
#ifdef _MSC_VER
505+
#define CPP2_FORCE_INLINE [[msvc::forceinline]]
506+
#else
507+
#define CPP2_FORCE_INLINE __attribute__((always_inline))
508+
#endif
509+
504510
#define CPP2_UFCS(FUNCNAME,PARAM1,...) \
505-
[](auto&& obj, auto&& ...params) { \
511+
[](auto&& obj, auto&& ...params) CPP2_FORCE_INLINE { \
506512
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); }) { \
507513
return std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); \
508514
} else { \
@@ -511,7 +517,7 @@ class out {
511517
}(PARAM1, __VA_ARGS__)
512518

513519
#define CPP2_UFCS_0(FUNCNAME,PARAM1) \
514-
[](auto&& obj) { \
520+
[](auto&& obj) CPP2_FORCE_INLINE { \
515521
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(); }) { \
516522
return std::forward<decltype(obj)>(obj).FUNCNAME(); \
517523
} else { \
@@ -522,7 +528,7 @@ class out {
522528
#define CPP2_UFCS_REMPARENS(...) __VA_ARGS__
523529

524530
#define CPP2_UFCS_TEMPLATE(FUNCNAME,TEMPARGS,PARAM1,...) \
525-
[](auto&& obj, auto&& ...params) { \
531+
[](auto&& obj, auto&& ...params) CPP2_FORCE_INLINE { \
526532
if constexpr (requires{ std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(params)>(params)...); }) { \
527533
return std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (std::forward<decltype(params)>(params)...); \
528534
} else { \
@@ -531,7 +537,7 @@ class out {
531537
}(PARAM1, __VA_ARGS__)
532538

533539
#define CPP2_UFCS_TEMPLATE_0(FUNCNAME,TEMPARGS,PARAM1) \
534-
[](auto&& obj) { \
540+
[](auto&& obj) CPP2_FORCE_INLINE { \
535541
if constexpr (requires{ std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (); }) { \
536542
return std::forward<decltype(obj)>(obj).template FUNCNAME CPP2_UFCS_REMPARENS TEMPARGS (); \
537543
} else { \

0 commit comments

Comments
 (0)