Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
New C++ Insights Episode
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <memory> #include <type_traits> namespace detail { template <typename> struct fn_types; template <typename R, typename... ARG_Ts> struct fn_types<R(ARG_Ts...)> { using type = R(ARG_Ts...); }; template <typename R, typename... ARG_Ts> struct fn_types<R(ARG_Ts...) const> { using type = R(ARG_Ts...); }; template <typename R, typename... ARG_Ts> struct fn_types<R(ARG_Ts...) noexcept> { using type = R(ARG_Ts...); }; template <typename R, typename... ARG_Ts> struct fn_types<R(ARG_Ts...) const noexcept> { using type = R(ARG_Ts...); }; template <typename SIG_T> using fn_types_t = typename fn_types<SIG_T>::type; static_assert(std::is_same_v<fn_types_t<void(int)>, void(int)>); static_assert(std::is_same_v<fn_types_t<int(void) noexcept>, int()>); static_assert(std::is_same_v<fn_types_t<int(bool) const noexcept>, int(bool)>); static_assert(std::is_same_v<fn_types_t<char(int) const throw()>, char(int)>); } // namespace detail template <typename SIG_T, typename = detail::fn_types_t<SIG_T>> class function_ref; template <typename SIG_T, typename R, typename... ARG_Ts> class function_ref<SIG_T, R(ARG_Ts...)> {}; static_assert(std::is_trivial_v<function_ref<int()>>); int main() { { [[maybe_unused]] function_ref<int()> fnref; [[maybe_unused]] function_ref<int() const> cfnref; [[maybe_unused]] function_ref<int() noexcept> exfnref; [[maybe_unused]] function_ref<int() const noexcept> cexfnref; } }
Insight:
Console: