Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Turner lefticus

View GitHub Profile
View iife.cpp
#include <chrono>
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
std::vector<std::vector<std::string>> classic(const int num_vecs, const int vec_size)
{
std::vector<std::vector<std::string>> retval;
@lefticus
lefticus / iife.cpp
Last active Feb 5, 2019
Immediately-invoked Function Expressions in C++
View iife.cpp
#include <chrono>
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
std::string to_string(const int i)
{
std::stringstream ss;
ss << i;
@lefticus
lefticus / chaiscript_inheritance.cpp
Created Oct 13, 2014
Example of Emulating Inheritance in ChaiScript and Sharing with C++
View chaiscript_inheritance.cpp
#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>
class BaseClass
{
public:
BaseClass()
{
}
@lefticus
lefticus / function_types.cpp
Last active Aug 29, 2015
function param deduction
View function_types.cpp
#include <tuple>
#include <iostream>
#include <typeinfo>
template<typename Ret>
struct function_type
{
};
template<typename Ret>
View chaiscript_overview.chai
// ChaiScript supports the normal kind of control blocks you've come to expect from
// C++ and JavaScript
if (5 > 2) {
print("Yup, 5 > 2");
} else if (2 > 5) {
// never gonna happen
} else {
// really not going to happen
View chaiscript_errorhandling.chai
// ChaiScript's primary error handling is exceptions, just like C++, and uses C++
// exceptions internally. This means that exceptions can be shared / passed / handled
// between ChaiScript and C++
// catching chaiscript errors inside of chaiscript
try {
eval("BLARG")
} catch (e) {
print("Error while processing eval statement"))
}
View chaiscript_fp.chai
// ChaiScript supports normal functional programming paradigms, with automatic overload resolution
var plus = `+` // get a reference to the function object representing all known `+` functions
print(plus("a", "b")) // prints "ab"
print(plus(1 , 3)) // prints "4"
// print(plus("a" , 3)) // generates a runtime error, no string + int operator available
// Back ticks are only necessary for capturing operator functions
View chaiscript_oop.chai
// ChaiScript has its own simple object model and works well with object
// oriented C++
// There is no difference between a function and a method, it's just syntactic sugar
var s = "mystring".size() // returns 8
var s2 = size("mystring") // returns 8
// class syntax
View run_ci.rb
#!/usr/bin/env ruby
require 'fileutils'
if ARGV.length < 4
puts "Usage: #{__FILE__} <buildfolder> [options] <testruntrueorfalse> <githubtoken> <repositoryname> (<repositoryname> ...)"
abort("Not enough arguments")
end
puts "starting CI system"
View codingstandards-0-automatedanalysis.md

THIS DOCUMENT

IS OUT OF

DATE

See https://github.com/lefticus/cppbestpractices/blob/master/00-Table_of_Contents.md Instead!

C++ Coding Standards Part 0: Automated Code Analysis

Automated analysis is the main advantage to working with a modern statically typed compiled language like C++. Code analysis tools can inform us when we have implemented an operator overload with a non-canonical form, when we should have made a method const, or when the scope of a variable can be reduced.

You can’t perform that action at this time.