Skip to content

Instantly share code, notes, and snippets.

#include <sys/stat.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc != 2)
{
return 0;
}
#include <utility>
template <template <typename...> class TemplateClass, typename... Args>
TemplateClass<Args...> make(Args&&... args)
{
return TemplateClass<Args...>(std::forward<Args>(args)...);
}
int main()
{
@sguzman
sguzman / Git selective maintenance
Last active August 29, 2015 13:56
gitignore exclusion rule - ignore everything except ...
*
# file1
!..
# file2
!..
# And so on
...
@sguzman
sguzman / pair-print.cpp
Last active August 29, 2015 13:56
Print a pair
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1,T2> pa)
{
return os << pa.first << ' ' << pa.second;
}
@sguzman
sguzman / memoization-example.cpp
Created March 2, 2014 06:30
An example of dynamic programming using fibonacci
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <exception>
#include <string>
namespace
{
using ulli = unsigned long long;
@sguzman
sguzman / gperf-template
Created March 2, 2014 09:22
Handy gperf invocation
gperf -L C++ -H hasher -N lookup -Z Hash -l -o -7 -C -E -I -G -t
@sguzman
sguzman / Makefile
Created March 2, 2014 19:39
Useful makefile template
CXX=clang++
FILE=prog2
SRCEXT=cpp
HEADEXT=hpp
WARNINGS=-Weverything -Werror -pedantic -pedantic-errors -Wno-c++98-compat -Wno-unused-macros
CXXFLAGS=-std=c++11 -g -O0 $(WARNINGS)
PCH=-x c++-header
@sguzman
sguzman / tuple-print.cpp
Created March 4, 2014 04:08
Print tuples - got it from http://ideone.com/Rihfre
#include <iostream>
#include <tuple>
namespace aux{
template<std::size_t...> struct seq{};
template<std::size_t N, std::size_t... Is>
struct gen_seq : gen_seq<N-1, N-1, Is...>{};
template<std::size_t... Is>
@sguzman
sguzman / print-head-tail.cpp
Created March 4, 2014 06:41
How to print a list with spaces inserted inbetween without worrying about adding extra spaces at the end or checking for a one time condition for all iterations
#include <iostream>
#include <functional>
int main(int argc, char *argv[])
{
auto printHead = [] (int num)
{
std::cout << num;
};
@sguzman
sguzman / print-anything.cpp
Last active August 29, 2015 13:57
Printing anything using variadic templates
#include <iostream>
static inline void print (void)
{}
template <typename Head, typename... Tail>
static inline void print (Head h, Tail... t)
{
std::cout << h << std::endl;
print(t...);