Skip to content

Instantly share code, notes, and snippets.

View lefticus's full-sized avatar

Jason Turner lefticus

View GitHub Profile
@lefticus
lefticus / chaiscript_inheritance.cpp
Created October 13, 2014 05:21
Example of Emulating Inheritance in ChaiScript and Sharing with C++
#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>
class BaseClass
{
public:
BaseClass()
{
}
@lefticus
lefticus / iife.cpp
Last active July 13, 2021 15:01
Immediately-invoked Function Expressions in C++
#include <chrono>
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
std::string to_string(const int i)
{
std::stringstream ss;
ss << i;
#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;
var func = fun(){
var ret = 0;
for (var i = 0; i < 1000000; ++i) {
ret += i;
}
return ret;
}
// async takes a 0 parameter function object which is run asynchronously and
// returns a Boxed_Value (ie, any value, including void, should work)
@lefticus
lefticus / generator.chai
Last active August 29, 2015 14:22
chaiscript generator proposal
// Generator class
class Generator
{
var has_value;
var value_holder;
var params;
var func;
// empty Generator - no value contained
repositories:
- "ChaiScript/ChaiScript"
#include <iostream>
#include <memory>
#include <vector>
#include <algorithm>
#include <type_traits>
template< class ... > using void_t = void;
template< class T , class = void >
struct is_dereferenceable : std::false_type
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
template<typename ... T>
std::vector<std::string> to_strings(const T& ... t)
{
std::stringstream ss;
return { (ss.str(""), ss << t, ss.str())... };
#include <vector>
int main()
{
// initialize a vector of integers. For the purposes of this example let's assume we *need* a vector
std::vector<int> v {1, 2, 3, 4, 5, 6, 1012, 1094};
}