Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fixed
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
#include <iostream> #include <tuple> template <typename F, typename... T1s, typename T2> auto detect(F&& f, std::tuple<T1s...>&&, T2&&) -> decltype(f(std::declval<T1s>()...)); template <typename F, typename T1, typename... T2s> auto detect(F&& f, T1&&, std::tuple<T2s...>&&) -> decltype(f(std::declval<T2s>()...)); template<typename T> struct Printer { T fn; explicit Printer(T _fn) : fn(std::move(_fn)) { } //das print, falls fn 1 Parameter nimmt template <typename U> auto print_(U& fn) -> decltype(fn(1)) { return fn(1); } //das print, falls fn 2 Parameter nimmt template <typename U, int = 0> auto print_(U& fn) -> decltype(fn(1, 2)) { return fn(1, 2); } auto print() {return print_(fn);} static int get_source(); static T get_function(); using value_type = decltype(detect(get_function(), std::make_tuple(get_source()), std::make_tuple(get_source(), 0))); }; int main() { auto fn = [](auto&& x) { std::cout << x; return 1; }; Printer<decltype(fn)>(fn).print(); auto fn2 = [](auto&& x, auto&& y) { std::cout << x << y; return 2; }; Printer<decltype(fn2)>(fn2).print(); Printer<decltype(fn2)>::value_type x = 4; (void)x; }
cl.exe
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 2,36 sec, absolute running time: 0,33 sec, absolute service time: 2,71 sec
edit mode
|
history
112