Last active
November 27, 2017 07:35
-
-
Save swkwon/50f40563bb0e1ca2bb82cd414c39cbb8 to your computer and use it in GitHub Desktop.
type deduction in auto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---------------------------------- | |
// example 1 | |
auto x = 26; // x is int | |
const auto cx = x; // cx is const int | |
const auto& rx = x; // rx is const int& | |
auto&& uref1 = x; // uref1 is int& | |
auto&& uref2 = cx; // uref2 is const int& | |
auto&& uref3 = 27; // uref3 is int&& | |
// ---------------------------------- | |
// example 2 | |
const char name[] = "Takkar"; | |
auto arr1 = name; // arr1 is const char* | |
auto& arr2 = name; // arr2 is const char(&)[7] | |
// ---------------------------------- | |
// example 3 | |
void some(int, double); | |
auto f1 = some; // f1 is void (*)(int, double); | |
auto& f2 = some; // f2 is void (&)(int, double); | |
// ---------------------------------- | |
// example 4 | |
int x = {3}; // x is int, value is 3. | |
auto y = {3}; // y is std::initializer_list<int> | |
auto z{3}; // z is std::initializer_list<int> | |
// ---------------------------------- | |
// example 5 | |
auto x = {3, 4, 5}; // x is std::initializer_list<int> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment