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
const std::string HolaMundo("Hola Mundo!"); | |
// auto se deduce como std::string | |
// y copiara el std::string HolaMundo | |
auto copia() { return HolaMundo; } | |
// auto se deduce como const std::string & | |
auto &referencia() { return HolaMundo; } | |
// auto se deduce como const std::string & |
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
// Declaracion de la funcion segunda | |
auto segunda(); | |
// Definicion de la funcion primera, el tipo de retorno | |
// se deduce como lo que devuelva la funcion segunda | |
auto primera() { return segunda(); } | |
// Error! no podemos deducir el retorno de la | |
// funcion segunda! | |
auto segunda() { return primera(); } |
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
auto Ackermann(int m, int n) | |
{ | |
if (m == 0) | |
// De aqui deducimos que | |
// el tipo de retorno sera int | |
return n + 1; | |
else if (n == 0) | |
// De aqui deducimos que | |
// el tipo de retorno sera | |
// lo que devuelva Ackerman |
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
auto haz_algo(int valor) | |
{ | |
switch (valor & 0b11) | |
{ | |
case 0b00: | |
return 0; // devuelve int | |
case 0b01: | |
return .0; // devuelve double | |
case 0b10: | |
return '0'; // devuelve char |
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
template <typename T> auto haz_algo(T valor) | |
{ | |
return valor; | |
} | |
// La funcion esta especializada para int | |
// su retorno es igualmente deducido | |
template <> auto haz_algo(int valor) | |
{ | |
return valor + 1; |
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
template <typename T> auto haz_algo(T valor) | |
{ | |
// de aqui se deduce que el tipo | |
// de retorno sera lo que sea T | |
return valor; | |
} |
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
auto haz_algo(); // Declaracion de la funcion | |
auto haz_algo(); // Otra declaracion de la funcion | |
auto haz_algo(); // Declaramos otra vez la funcion | |
// Error! no podemos llamar a una funcion no definida! | |
int hecho = haz_algo(); | |
// Definimos la funcion, cuyo retorno se deduce int | |
auto haz_algo() | |
{ |
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
// No sabemos (aun) el tipo de retorno, | |
// ya lo averiguaremos mas adelante. | |
auto haz_algo(); | |
struct objeto | |
{ | |
// Tampoco sabemos (aun) el tipo de retorno, | |
// de esta funcion, ya lo averiguaremos... | |
auto funcion(); | |
}; |
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
// se deduce que el tipo de retorno sera double | |
// en el sufijo del retorno de la funcion | |
auto divide(int a, double b) -> decltype(a / b) | |
{ | |
return a / b; | |
} |
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
auto cero() | |
{ | |
// de aqui se deduce que el tipo de retorno es int | |
return 0; | |
} | |
auto divide(int a, double b) | |
{ | |
// de aqui se deduce que el tipo de retorno sera double | |
return a / b; |