Skip to content

Instantly share code, notes, and snippets.

@jasonbeach
jasonbeach / gist:215c23ea6b3b4b4b246f4455d32daba0
Created April 25, 2020 05:15
Find minimum element while transforming the elements
// This is meant to minimic std::minimum_element, but allows you to transform the
// element in some way. We could use std::minimum_element, but the transform function
// would be evaluated twice as many times as it needs to be as it's results aren't
// cached. This caches the value.
template<class ForwardIt, class UnaryOperation>
ForwardIt min_transformed_element(ForwardIt first, ForwardIt last, UnaryOperation unary_op)
{
if (first == last) return last;
@jasonbeach
jasonbeach / string_zipper.cpp
Created April 18, 2020 19:40
Parse two lists of numbers and zip them into a vector of pairs
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
struct Pos{
float x = 0;
float y = 0;