Skip to content

Instantly share code, notes, and snippets.

// demonstrating use of Eigen::Map
#include <iostream>
#include <vector>
#include <Eigen/Dense>
int main() {
using namespace Eigen;
std::vector<float> foo{1.0, 2.0, 3.0, 4.0};
Map<Matrix<float, Dynamic, 1>> foom(foo.data(), foo.size());
IOFormat OctaveFmt(StreamPrecision, 0, ", ", ";\n", "", "", "[", "]");
@jefftrull
jefftrull / gist:f5d8ecb218815523f5d7af836eea8b9a
Created April 25, 2017 17:25
Cannot sort with boost::iterator::zip_iterator
// experimenting with zip iterator and sort
#include <vector>
#include <iostream>
#include <boost/iterator/zip_iterator.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
using zip_it = boost::zip_iterator<std::tuple<std::vector<std::size_t>::iterator,
std::vector<std::size_t>::iterator,
@jefftrull
jefftrull / gist:983d783cf508249e5352de8e844a27cb
Created September 20, 2016 05:36
Interesting (possibly wrong) synthesized attribute behavior
#include <iostream>
#include <boost/spirit/include/qi.hpp>
#include <boost/optional.hpp>
#include <boost/optional/optional_io.hpp>
int main() {
using namespace std;
// parsing parentheses that may or may not contain integers
string in("(10) () (20)");
@jefftrull
jefftrull / gist:0d7ecfef151c39885a7633d7547df8e6
Created April 18, 2016 16:06
*qi::string is compatible with both std::string (concatenation) and std::vector<std::string> (push_back) attributes
#include <string>
#include <vector>
#include <boost/spirit/include/qi.hpp>
using string_it_t = std::string::const_iterator;
int main() {
using namespace boost::spirit;
using namespace boost::spirit::qi;
@jefftrull
jefftrull / gist:2fbbd52a0dec25c1e14d1e69af3361ac
Created April 18, 2016 03:21
Spirit sequence-of-sequences: struct vs. string
// To see if a rule whose attribute is sequence-of-sequence can make appends happen somehow
#include <string>
#include <vector>
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
struct tiny {
std::string thing;
@jefftrull
jefftrull / test_ub.cpp
Created March 5, 2016 00:14
Simple test of signed overflow UB
#include <iostream>
#include <cstdint>
#include <limits>
int main(int argc, char **argv) {
std::int32_t i = std::numeric_limits<int32_t>::max();
i++; // signed overflow
if (i < 0) {
std::cerr << "i<0 and i=" << i << "\n"; // "expected" or "safe" result (-O1)
} else {
@jefftrull
jefftrull / gist:5971433
Created July 11, 2013 00:20
Test code for jqm-datepicker #282
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" />
<link rel="stylesheet" type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
<!-- Optional Mousewheel support: https://github.com/brandonaaron/jquery-mousewheel -->
@jefftrull
jefftrull / gist:5544308
Created May 8, 2013 22:56
Using semantic actions with synthesized attributes. Do the attributes only get matched with the part of the rule that lacks actions? Or the whole thing?
// a test case for combining semantic actions with synthesized attributes in the same rule
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
// An attempt to generically parse expressions like this:
// <token> <int> ;
// - <some-expr> ;
// - <some-expr> ;
// - <some-expr> ; <- exactly as many times as given by <int> above
// END <token>
// where <token> is a string, and <some-expr> is a rule with attribute A
// the synthesized attribute of the result should be a fusion sequence of A
// Furthermore the resulting grammar should check the number of <some-expr> and ensure it
// matches the supplied <int>, with (ideally) a suitable error message
@jefftrull
jefftrull / crash.cpp
Created February 20, 2013 00:21
Test case for gcc 4.7.2 crash ("internal compiler error: in get_expr_operands, at tree-ssa-operands.c:1035")
// A test case for gcc 4.7.2 crash
// Author: Jeff Trull <jeff.trull@ciere.com>
#include <vector>
#include <algorithm>
template<class Base>
class MyClass : Base
{
public: