Skip to content

Instantly share code, notes, and snippets.


Daryle Walker CTMacUser

  • Connecticut, USA
View GitHub Profile
View zipWith_demo.cpp
// Taken from the final code I provided as an answer to a StackOverflow query
// at <>.
// Copyright 2012 by Daryle Walker
#include <algorithm> // min
#include <cassert> // assert
#include <cmath> // pow
#include <cstddef> // size_t
#include <iostream> // cout
#include <iterator> // back_inserter, begin, end
CTMacUser / times.cpp
Created Apr 2, 2013
A custom literal suffix that returns an object that takes a function (object) for generic looping. C++11 required. The fact that the idea is theoretically and actually possible is amazing. I don't know if that's good or bad, yet.
View times.cpp
Copyright (C) 2013 by Daryle Walker
Based on posts off the Boost mailing lists on 2013-Jan-31 by Tim
Blechmann and TONGARI. C++11 is required; according to Live Work
Space's code-runner (on 2013-Apr-1), only Clang >= 3.2 and
GCC >= 4.7 accept it.
The original post (Tim Blechmann) of the 7 in the thread:
CTMacUser / slice.cpp
Created Apr 3, 2013
An example program to create a variadic function that computes a chain of indexing expressions. It's a solution of a problem I posted at
View slice.cpp
Demostration of variadic function template that runs a series of indexing
expressions. Based of a problem I posted at
Copyright (C) 2013 Daryle Walker
I'm letting anyone use this code under the Boost Software License.
#include <cassert>
#include <cstddef>
CTMacUser / remove_some_extents.cpp
Created Apr 25, 2013
Use when a built-in array types needs extents to be stripped, but the amount to strip is between one and all (exclusive). I thought I needed this for another project, but I ended up not needing it (yet). So it's here so I won't forget, and for posterity.
View remove_some_extents.cpp
// Copyright 2013 Daryle Walker.
// Distributed under the Boost Software License, Version 1.0. (See a copy at
// <>.)
#include <cstddef>
CTMacUser / Lucky Numbers.swift
Last active Apr 2, 2016
Using Swift to demonstrate the Sieve of Eratosthenes
View Lucky Numbers.swift
import Foundation
Run an incremental counter, but return only the values that survive the "lucky number" process.
The process is to list all the positive integers, then filter out entries in stages. For all the numbers in a stage, let *N* be the first unfiltered number that is neither 1 nor been already been used as a filter seed for a previous stage, and filter out every Nth number. The first pass uses 2 and therefore filters out every second number, i.e. the even numbers. The second pass uses 3 and therefore filters out every third number that survived the 2-stage. The third pass uses 7 and therefore filters out every seventh number that survived both the 2- and 3-stages. The fourth pass uses 9 and therefore filters out every ninth number that survived the 2-, 3-, and 7-stages. (Note that 2 is the only seed that eliminates itself in its filter. Some definitions of lucky numbers avoid this irregularity by starting with the odd positive integers.)
public struct LuckyNumberGenerator<C
CTMacUser / AdjacentDifference.swift
Last active Mar 23, 2016
Using Swift to demonstrate finding powers with just adding (and some prep work).
View AdjacentDifference.swift
import Foundation
A generator for the distance between two adjacent elements from another generator.
public struct AdjacentDifferenceGenerator<Source: GeneratorType where Source.Element: Strideable>: GeneratorType {
/// The last value read, needed to calculate the difference
private var queue: (Source.Element?, Source.Element?)
CTMacUser / Mismatch.swift
Created Jul 6, 2016
Proposal and Code to add C++'s mismatch algorithm to Swift.
View Mismatch.swift
extension CollectionType {
func diverges<PossiblePrefix: CollectionType where PossiblePrefix.Generator.Element == Generator.Element>(from possiblePrefix: PossiblePrefix, isEquivalent: (Generator.Element, Generator.Element) throws -> Bool) rethrows -> (Index, PossiblePrefix.Index) {
var selfIndex = startIndex
var fromIndex = possiblePrefix.startIndex
while selfIndex != endIndex && fromIndex != possiblePrefix.endIndex {
let areEqual = try isEquivalent(self[selfIndex], possiblePrefix[fromIndex])
guard areEqual else {
CTMacUser /
Last active Jun 28, 2017
Swift proposal for object aliases
CTMacUser /
Last active Jul 29, 2017
Swift proposal for strong type-aliases

Alternative Interface Value Types


This proposal adds a nominal type whose structure is an existing value type and interface can be customized, including selective use of the original type's interface. It is equivalent to the type declaration feature in Go, newtype in Haskell, and the oft-requested "strong typedef" in C(++).

CTMacUser /
Last active Dec 12, 2019
Swift proposal for fixed-size array types
You can’t perform that action at this time.