This file contains hidden or 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
constexpr int Sum(const int a, const int b) { | |
return a + b; | |
} | |
constexpr int main(int argc, char **argv) { | |
const int val = Sum(1, 2); | |
return 0; | |
} |
This file contains hidden or 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
int main() { | |
constexpr int val = 1 + 2; | |
return 0; | |
} |
This file contains hidden or 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
int Sum(const int a, const int b) { | |
return a + b; | |
} | |
int main(int argc, char **argv) { | |
const int val = Sum(1, 2); | |
return 0; | |
} |
This file contains hidden or 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
int main() { | |
const int val = 1 + 2; | |
return 0; | |
} |
This file contains hidden or 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
void callback(const int *value) { | |
int *mutableValue = const_cast<int*>(value); | |
// we can now modify value, but the result is undefined | |
*mutableValue = 100; | |
std::cout << "mutableValue: " << *mutableValue << "\n"; | |
} | |
void library_code() { | |
const int value = 10; | |
callback(&value); |
This file contains hidden or 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
void callback(const int *value) { | |
int *mutableValue = const_cast<int*>(value); | |
// we can now modify value | |
} | |
void library_code() { | |
int value = 10; | |
callback(&value); | |
} |
This file contains hidden or 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
void callback(int *value) { | |
const int *immutableValue = const_cast<const int*>(value); | |
// from this point | |
// we use immutableValue to ensure const correctness | |
} | |
void library_code() { | |
int value = 10; | |
callback(&value); | |
} |
This file contains hidden or 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
Output Process(const Input *input) { | |
return Output(); | |
} | |
int main() { | |
Input input; | |
Output output = Process(&input); | |
return 0; | |
} |
This file contains hidden or 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
int main() { | |
Input input; | |
const Input *input2 = &input; | |
Output output = Process(*input2); | |
return 0; | |
} |
This file contains hidden or 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
Output Process (Input input) { | |
return Output(); | |
} | |
int main() { | |
Input input; | |
const Input& input2 = input; | |
Output output = Process(input2); | |
return 0; |