Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
krysseltillada / Sales_data.hpp
Created October 29, 2015 18:15
own implementation of std::tuple, std::pair, std::equal_range
#ifndef SALES_DATA_H
#define SALES_DATA_H
#include <string>
#include <iostream>
class Sales_data {
@krysseltillada
krysseltillada / Sales_data.cpp
Created October 28, 2015 18:28
SearchBook class
#include "SearchBook.hpp"
double Sales_data::avg_price () const {
return units_sold / revenue;
}
Sales_data &Sales_data::operator += (const Sales_data &lhs) {
units_sold += lhs.units_sold;
revenue += lhs.revenue;
return *this;
@krysseltillada
krysseltillada / ts.cpp
Created October 18, 2015 15:31
template specialization
#include <iostream> /// std::cout
#include <cstdlib> /// #EXIT_SUCCESS --> macro definition
template <typename T>
T sum (const T &t1, const T &t2) {
return t1 + t2;
}
///******** template specializations of <T> sum ******************///
@krysseltillada
krysseltillada / Memory.hpp
Created October 17, 2015 13:50
createResource template
#pragma once
/**
@ C++ Primer 5th edition exercise 16.51:
@Author: Kryssel Tillada
@File : Memory.hpp
@Date : 10 / 17 / 15
@@ note : if pragma macro does not work define your own header guard
@ added createResource tmp for allocating resource for smart_ptr tmp
@krysseltillada
krysseltillada / vt.cpp
Created October 16, 2015 17:51
variadic template
#include <iostream> /// std::cerr
#include <cstdlib> /// #EXIT_SUCCESS
template <typename T>
void errorMsg (const T &t) {
std::cerr << t << std::endl; /// this template function will be called when the size of the pack is 1 because this function
} /// is the best match for the call because of its exactly one argument and is a more specialized function
template <typename T, typename ...Tv> /// template parameter pack expands its list of elements that deduced from template arguments and applies a pattern to the corresponding function parameter pack
void errorMsg (const T &t1, const Tv &...tv) { /// that is each element has const & Tv whatever type had deduced
@krysseltillada
krysseltillada / mm.cpp
Created October 15, 2015 15:02
memory handling (vectors)
#include <iostream>
int main ()
{
int sz = 0, unalloc_space = 1;
int *elem, input = 0, *alloc_mem = nullptr, *temp_mem;
while (std::cin >> input) {
if (alloc_mem == nullptr) {
@krysseltillada
krysseltillada / Memory.hpp
Last active October 3, 2015 18:12
const_ptr <T, D> && smart_ptr <T, D>
#pragma once
template <typename defType>
class defDeleter {
public:
void operator () (defType *);
private:
bool setState;
@krysseltillada
krysseltillada / Vec.hpp
Created September 30, 2015 18:44
Vec template
#pragma once
#include <memory>
#include <vector>
template <typename> class Vec;
template <typename getType>
bool operator == (const Vec <getType> &, const Vec <getType> &);
#pragma once
#include <iostream>
template <unsigned, unsigned> class ScreenTemplate;
template <unsigned getH, unsigned getW>
std::ostream &operator << (std::ostream &, const ScreenTemplate <getH, getW> &);
template <unsigned getH, unsigned getW>
@krysseltillada
krysseltillada / Storage.hpp
Created September 30, 2015 17:49
Storage template
#ifndef STORAGE_HEADER
#define STORAGE_HEADER
#include <memory>
#include <vector>
template <typename> class ptrStorage;
template <typename> class Storage;
template <typename getType>