Various C std shortcuts. This will make your life better and your code readers' lives worse, but don't worry, no one reads your code anyway! You can add this via CPM.cmake and shoot in your foot once more, because this thing does not use any namespaces! Why, you may ask. The reason is that this repo will be remade to be used with c 20 modules, but there is a catch: C 20 IS NOT YET SUPPORTED!
Currently, it is suitable for testing and learning. When you learn or test certain language concepts and things, you want to as less code as possible. This is why this library was created.
I don't recommend using it in headers for now, especially when creating libraries, since it'll make the life of the developers that will build on top of your code annoying. But the C 20 modules fix this problem via isolation, so you don't have to worry about anything if you're using this as a module. I'll make the module support for this project, when C 20 is out in my compiler.
include(cmake/CPM.cmake)
CPMAddPackage("gh:RIGIK93/shortcuts.cmake#main")
# ...
# Link to the created library shortcuts
target_link_libraries(myapp PRIVATE shortcuts)
I've wrapped std::cout
around the print function
#include "print.h"
#include <string>
#include <vector>
int main() {
print("Hello world!"); // outputs: Hello world!
print("Hello", "world!"); // outputs: Hello world!
std::vector<std::string> a {
"Hello",
"world!"
}
print(a); // outputs: [Hello, world!]
return 0;
}
The vector is shorter now!
#include "vec.h"
int main() {
vec<Object> foo; // same as: std::vector<Object> foo;
return 0;
}
The string is shorter now!
#include "str.h"
int main() {
str something("something"); // same as: std::string something("something");
str cool = "cool"; // same as: std::string cool = "cool";
return 0;
}
Shared Pointer:
#include "sptr.h"
int main() {
sptr<Object> smart_pointer(new Object()); // same as: std::shared_ptr<Object> smart_pointer(new Object());
return 0;
}
Unique Pointer:
#include "uptr.h"
int main() {
uptr<Object> smart_pointer(new Object()); // same as: std::unique_ptr<Object> smart_pointer(new Object());
return 0;
}
And if you want to use both, I created a shortcut just for you!
#include "ptrs.h"
int main() {
sptr<Object> smart_pointer(new Object()); // same as: std::shared_ptr<Object> smart_pointer(new Object());
uptr<Object> smart_pointer(new Object()); // same as: std::unique_ptr<Object> smart_pointer(new Object());
return 0;
}