Skip to content

Instantly share code, notes, and snippets.

View illescasDaniel's full-sized avatar
💻
Learning something new

Daniel Illescas Romero illescasDaniel

💻
Learning something new
View GitHub Profile
@illescasDaniel
illescasDaniel / toUpperToLower.cpp
Created October 24, 2016 11:40
String toUpper & toLower [C++]
#include <iostream>
#include <vector>
#include <string>
using namespace std;
string toUpper(string str);
string toLower(string str);
vector<string> toUpper(vector<string> strings);
vector<string> toLower(vector<string> strings);
@illescasDaniel
illescasDaniel / outOfRange.cpp
Created October 24, 2016 11:46
Try catch with vector [C++]
#include <iostream>
#include <vector>
#include <stdexcept>
#define varName(_variable_) #_variable_
using namespace std;
int main(int argc, char *argv[]) {
@illescasDaniel
illescasDaniel / checkNumber.cpp
Last active October 24, 2016 11:58
Check number try catch [C++]
#include <iostream>
#include <stdexcept>
#include <string>
using namespace std;
int main() {
constexpr uint16_t maxAge = 100;
bool isInvalid;
@illescasDaniel
illescasDaniel / literals.cpp
Last active November 26, 2016 15:45
User-defined literals [C++]
#include <iostream>
#include <string>
using namespace std;
auto operator "" _x2(unsigned long long number) {
return number * 2;
}
string operator "" _upper(char const * str, size_t size) {
@illescasDaniel
illescasDaniel / switchStrings.cpp
Created November 26, 2016 15:51
Switch with strings [C++]
#include <iostream>
#include <map>
#include <vector>
using namespace std;
void setupSwitchWithStrings(vector<string> strings, string& value, map<string,uint16_t>& map);
void toLower(string& str);
int main() {
@illescasDaniel
illescasDaniel / staticMembers.cpp
Created November 26, 2016 15:53
Static members [C++]
#include <iostream>
using namespace std;
struct Box {
static int objectCount;
static constexpr int test = 20;
Box() {
@illescasDaniel
illescasDaniel / asserts.cpp
Created November 26, 2016 15:59
Assert [C++]
#include <iostream>
#include <cassert>
using namespace std;
int main(int argc, char *argv[]) {
uint16_t number1 = 10, number2 = 20;
assert(number1 + number2 == 30);
@illescasDaniel
illescasDaniel / boolalpha.cpp
Created November 26, 2016 16:00
boolalpha [C++]
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
boolalpha(cout);
bool isBig = false;
bool hasGF = true;
@illescasDaniel
illescasDaniel / xAssert.cpp
Last active November 30, 2016 12:35
Custom assertion [C++]
#include <iostream>
#define xAssert(_condition, _message) if (bool(_condition) == false) { \
cerr << "Condition: " << (#_condition)<< "\nError: " << (_message) << endl; exit(1); }
using namespace std;
int main(int argc, char *argv[]) {
xAssert(1 + 2 == 2, "wrong result");
@illescasDaniel
illescasDaniel / guardFunction.cpp
Created December 26, 2016 12:33
Guard statement (from Swift) in C++
#include <iostream>
using namespace std;
// Guard function
template <typename Condition, typename Function>
bool guard(const Condition& condition, Function function) {
if (bool(!condition)) {
function();