Created
February 25, 2015 18:58
-
-
Save simonwo/f1be28ebcbf7a8787f19 to your computer and use it in GitHub Desktop.
These aliases make pointers and references look more like real types. See https://simonwo.net/code/clearer-cpp-types for more.
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
#pragma once | |
/* These type alias templates (introduced in C++11) allow | |
* us to template typedefs (via a different syntax). | |
* | |
* Here we are templating generic pointer and reference types | |
* so we could write ptr<T> instead of T*. | |
* | |
* See simonwo.net/code/clearer-cpp-types for more. | |
*/ | |
template <typename T> | |
using ptr = T*; | |
template <typename T> | |
using ref = T&; |
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
#include <iostream> | |
#include "cleartypes.h" | |
using std::cout; | |
using std::endl; | |
// http://ideone.com/5ybeb6 | |
int main() { | |
ptr<const char> text = "Hello, World!"; | |
cout << text << endl; | |
int i = 1; | |
ref<int> j = i; | |
j = 5; | |
cout << i << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment