mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-04-10 14:09:53 +08:00
support bazel complie this project and format code.
This commit is contained in:
26
learn_class/modern_cpp_30/SFINAE/sfinae paper/auto.cpp
Normal file
26
learn_class/modern_cpp_30/SFINAE/sfinae paper/auto.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by light on 20-1-6.
|
||||
//
|
||||
#include <iostream>
|
||||
|
||||
bool f();
|
||||
|
||||
auto test = f(); // Famous usage, auto deduced that test is a boolean, hurray!
|
||||
|
||||
|
||||
|
||||
// vvv t wasn't declare at that point, it will be after as a parameter!
|
||||
template<typename T>
|
||||
decltype(t.serialize()) g(const T &t) {} // Compilation error
|
||||
|
||||
// Less famous usage:
|
||||
// vvv auto delayed the return type specification!
|
||||
// vvv vvv the return type is specified here and use t!
|
||||
template<typename T>
|
||||
auto g(const T &t) -> decltype(t.serialize()) {} // No compilation error.
|
||||
|
||||
|
||||
auto myFunction() // Automagically figures out that myFunction returns ints.
|
||||
{
|
||||
return int();
|
||||
}
|
||||
Reference in New Issue
Block a user