Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Additional layer of indirection
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #include <type_traits> #include <iostream> int fn1() { return 1; } int fn2(int) { return 2; } template <typename FN_T, FN_T FN, typename DERIVED> class test_base { template <typename T = DERIVED, typename = std::enable_if_t<!T::fn_specified>> int fn() { return FN(); } public: int fn_indirect() { return static_cast<DERIVED*>(this)->fn(); } }; template <class FN_T> class test_derived : public test_base<typename FN_T::value_type, FN_T::value, test_derived<FN_T>> { public: static constexpr bool fn_specified = false; }; template <typename FN_T> class test_derived<std::integral_constant<FN_T, &fn2>> : public test_base<FN_T, &fn2, test_derived<std::integral_constant<FN_T, &fn2>>> { using base = test_base<FN_T, &fn2, test_derived<std::integral_constant<FN_T, &fn2>>>; friend base; public: static constexpr bool fn_specified = true; int fn() { return fn2(1); } }; int main(void) { test_derived<std::integral_constant<decltype(&fn1), &fn1>> x1; test_derived<std::integral_constant<decltype(&fn2), &fn2>> x2; std::cout << x1.fn_indirect() << " "; // comment next line out and it will work std::cout << x2.fn_indirect() << std::endl; return 0; }
cl.exe
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1,92 sec, absolute running time: 0,33 sec, absolute service time: 2,27 sec
edit mode
|
history
|
discussion
1 2