Index: doc/theses/mike_brooks_MMath/programs/lst-features-intro.run.cfa
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-features-intro.run.cfa	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-features-intro.run.cfa	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,62 @@
+#include <containers/list.hfa>
+
+
+int main() {
+
+
+
+
+
+
+
+struct req;
+P9_EMBEDDED_FWD_INFUNC(req, dlink(req))
+
+
+
+
+
+
+struct req {
+  int pri, rqr;
+  inline dlink(req);
+};
+
+dlist(req) reqs;
+
+req
+  r1 = {1, 42},
+  r2 = {2, 42};
+
+insert_first(reqs, r2);
+insert_first(reqs, r1);
+
+
+
+
+
+
+
+P9_EMBEDDED_INFUNC(req, dlink(req))
+
+
+
+
+
+
+
+
+
+
+
+while( req & cur = reqs`elems; cur`moveNext )
+    printf("{%d %d} ", cur.pri, cur.rqr);
+printf("\n");
+
+
+
+
+
+
+
+}
Index: doc/theses/mike_brooks_MMath/programs/lst-features-multidir.run.cfa
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-features-multidir.run.cfa	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-features-multidir.run.cfa	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,97 @@
+#include <containers/list.hfa>
+
+
+
+
+int main() {
+
+
+
+
+
+
+
+
+
+
+
+
+
+struct req {
+  int pri, rqr;
+  inline struct by_pri { inline dlink(req); };
+  inline struct by_rqr { inline dlink(req); };
+};
+
+
+
+
+
+// need to spice this case; can't forward declare nested struct
+P9_EMBEDDED_INFUNC(req, req.by_pri)
+P9_EMBEDDED_INFUNC(req, req.by_rqr)
+P9_EMBEDDED_INFUNC(req.by_pri, dlink(req))
+P9_EMBEDDED_INFUNC(req.by_rqr, dlink(req))
+
+
+
+
+
+dlist(req, req.by_pri) reqs_pri_global;
+dlist(req, req.by_rqr) reqs_rqr_42;
+dlist(req, req.by_rqr) reqs_rqr_17;
+dlist(req, req.by_rqr) reqs_rqr_99;
+
+struct req
+  r42a = {1, 42},
+  r42b = {2, 42},
+  r17a = {2, 17},
+  r17b = {3, 17},
+  r17c = {4, 17},
+  r99a = {3, 99};
+
+insert_first(reqs_pri_global, r17c);
+insert_first(reqs_pri_global, r99a);
+insert_first(reqs_pri_global, r17b);
+insert_first(reqs_pri_global, r42b);
+insert_first(reqs_pri_global, r17a);
+insert_first(reqs_pri_global, r42a);
+
+insert_first(reqs_rqr_42, r42b);
+insert_first(reqs_rqr_42, r42a);
+
+insert_first(reqs_rqr_17, r17c);
+insert_first(reqs_rqr_17, r17b);
+insert_first(reqs_rqr_17, r17a);
+
+insert_first(reqs_rqr_99, r99a);
+
+
+
+
+
+
+
+
+with(DLINK_VIA(req, req.by_pri)) {
+    while( req & cur = reqs_pri_global`elems; cur`moveNext )
+        printf("{%d %d} ", cur.pri, cur.rqr);
+    printf("| ");
+}
+
+with(DLINK_VIA(req, req.by_rqr)) {
+    while( req & cur = reqs_rqr_42`elems; cur`moveNext )
+        printf("{%d %d} ", cur.pri, cur.rqr);
+    printf("| ");
+    while( req & cur = reqs_rqr_17`elems; cur`moveNext )
+        printf("{%d %d} ", cur.pri, cur.rqr);
+    printf("| ");
+    while( req & cur = reqs_rqr_99`elems; cur`moveNext )
+        printf("{%d %d} ", cur.pri, cur.rqr);
+    printf("\n");
+}
+
+
+
+
+}
Index: doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction-byref.run.cpp
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction-byref.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction-byref.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,5 @@
+#include <cstdio>
+#include "lst-issues-attach-reduction.hpp"
+
+#define INTERPOSED_LIST_NS my
+#include "lst-issues-wrapped-byref.run.cpp"
Index: doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction-emplaced.run.cpp
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction-emplaced.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction-emplaced.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,5 @@
+#include <cstdio>
+#include "lst-issues-attach-reduction.hpp"
+
+#define INTERPOSED_LIST_NS my
+#include "lst-issues-wrapped-emplaced.run.cpp"
Index: doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction.hpp
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction.hpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-issues-attach-reduction.hpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,157 @@
+
+
+// excerpt of <sys/queue.h>, modified to work in C++ along with templates
+
+#define	LIST_HEAD(name, type)						\
+struct name {								\
+	type *lh_first;	/* first element */			\
+}
+
+#define	LIST_HEAD_INITIALIZER(head)					\
+	{ NULL }
+
+#define	LIST_ENTRY(type)						\
+struct {								\
+	type *le_next;	/* next element */			\
+	type **le_prev;	/* address of previous next element */	\
+}
+
+/*
+ * List functions.
+ */
+#define	LIST_INIT(head) do {						\
+	(head)->lh_first = NULL;					\
+} while (/*CONSTCOND*/0)
+
+#define	LIST_INSERT_AFTER(listelm, elm, field) do {			\
+	if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)	\
+		(listelm)->field.le_next->field.le_prev =		\
+		    &(elm)->field.le_next;				\
+	(listelm)->field.le_next = (elm);				\
+	(elm)->field.le_prev = &(listelm)->field.le_next;		\
+} while (/*CONSTCOND*/0)
+
+#define	LIST_INSERT_BEFORE(listelm, elm, field) do {			\
+	(elm)->field.le_prev = (listelm)->field.le_prev;		\
+	(elm)->field.le_next = (listelm);				\
+	*(listelm)->field.le_prev = (elm);				\
+	(listelm)->field.le_prev = &(elm)->field.le_next;		\
+} while (/*CONSTCOND*/0)
+
+#define	LIST_INSERT_HEAD(head, elm, field) do {				\
+	if (((elm)->field.le_next = (head)->lh_first) != NULL)		\
+		(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
+	(head)->lh_first = (elm);					\
+	(elm)->field.le_prev = &(head)->lh_first;			\
+} while (/*CONSTCOND*/0)
+
+#define	LIST_REMOVE(elm, field) do {					\
+	if ((elm)->field.le_next != NULL)				\
+		(elm)->field.le_next->field.le_prev = 			\
+		    (elm)->field.le_prev;				\
+	*(elm)->field.le_prev = (elm)->field.le_next;			\
+} while (/*CONSTCOND*/0)
+
+#define	LIST_FOREACH(var, head, field)					\
+	for ((var) = ((head)->lh_first);				\
+		(var);							\
+		(var) = ((var)->field.le_next))
+
+/*
+ * List access methods.
+ */
+#define	LIST_EMPTY(head)		((head)->lh_first == NULL)
+#define	LIST_FIRST(head)		((head)->lh_first)
+#define	LIST_NEXT(elm, field)		((elm)->field.le_next)
+
+
+
+
+
+
+
+namespace my {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+template<typename El>
+class list {
+    struct node {
+        LIST_ENTRY(node) links;
+        El elem;
+    };
+    LIST_HEAD(Impl, node);
+    Impl impl;
+  public:
+    list() {
+        LIST_INIT(&impl);
+    }
+    void push_front( const El & src ) {
+        node * n = new node();
+        n->elem = src;
+        LIST_INSERT_HEAD(&impl, n, links);
+    }
+    // ... `emplace` elided
+
+
+
+
+
+
+
+
+
+
+
+
+
+    template<typename... CtorArgs>
+    void emplace_front( CtorArgs... args ) {  
+        El tempEl{args...}; // (mock: avoid real emplacing to keep `struct node` simple; disucssion is about allocation, not copying)
+        push_front(tempEl);
+    }
+    class IType {
+        node* p;
+      public:
+        IType(node* p) : p(p) {}
+        bool operator!=(IType rhs) {return p != rhs.p;}
+        const El& operator*() {return p->elem;}
+        void operator++() { p = LIST_NEXT(p, links); }
+    };
+    IType begin() {return IType(LIST_FIRST(&impl)); }
+    IType end() {return IType(NULL); }
+
+
+
+
+};
+
+
+
+
+
+
+}
Index: doc/theses/mike_brooks_MMath/programs/lst-issues-intrusive.run.c
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-issues-intrusive.run.c	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-issues-intrusive.run.c	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,56 @@
+#include <sys/queue.h>
+#include <stdio.h>
+
+
+
+int main() {
+
+
+
+
+
+
+
+
+
+
+
+
+
+// C
+
+struct req {
+  int pri, rqr;
+  LIST_ENTRY(req) x;
+};
+
+LIST_HEAD(reql, req);
+
+struct reql reqs;
+LIST_INIT(&reqs);
+
+struct req
+  r1 = {1, 42},
+  r2 = {2, 42};
+
+LIST_INSERT_HEAD(
+  &reqs, &r2, x);
+LIST_INSERT_HEAD(
+  &reqs, &r1, x);
+
+
+
+
+
+
+
+
+
+
+
+struct req *cur;
+LIST_FOREACH(cur, &reqs, x)
+    printf("{%d %d} ", cur->pri, cur->rqr);
+printf("\n");
+
+}
Index: doc/theses/mike_brooks_MMath/programs/lst-issues-multi-static.run.c
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-issues-multi-static.run.c	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-issues-multi-static.run.c	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,82 @@
+#include <sys/queue.h>
+#include <stdio.h>
+
+
+
+int main() {
+
+
+
+
+
+
+
+
+
+
+
+
+
+struct req {
+  int pri, rqr;
+  LIST_ENTRY(req) by_pri;
+  LIST_ENTRY(req) by_rqr;
+};
+
+LIST_HEAD(reql, req);
+
+struct reql reqs_pri_global;
+struct reql reqs_rqr_42;
+struct reql reqs_rqr_17;
+struct reql reqs_rqr_99;
+
+LIST_INIT(&reqs_pri_global);
+LIST_INIT(&reqs_rqr_42);
+LIST_INIT(&reqs_rqr_17);
+LIST_INIT(&reqs_rqr_99);
+
+struct req
+  r42a = {1, 42},
+  r42b = {2, 42},
+  r17a = {2, 17},
+  r17b = {3, 17},
+  r17c = {4, 17},
+  r99a = {3, 99};
+
+LIST_INSERT_HEAD(&reqs_pri_global, &r17c, by_pri);
+LIST_INSERT_HEAD(&reqs_pri_global, &r99a, by_pri);
+LIST_INSERT_HEAD(&reqs_pri_global, &r17b, by_pri);
+LIST_INSERT_HEAD(&reqs_pri_global, &r42b, by_pri);
+LIST_INSERT_HEAD(&reqs_pri_global, &r17a, by_pri);
+LIST_INSERT_HEAD(&reqs_pri_global, &r42a, by_pri);
+
+LIST_INSERT_HEAD(&reqs_rqr_42, &r42b, by_rqr);
+LIST_INSERT_HEAD(&reqs_rqr_42, &r42a, by_rqr);
+
+LIST_INSERT_HEAD(&reqs_rqr_17, &r17c, by_rqr);
+LIST_INSERT_HEAD(&reqs_rqr_17, &r17b, by_rqr);
+LIST_INSERT_HEAD(&reqs_rqr_17, &r17a, by_rqr);
+
+LIST_INSERT_HEAD(&reqs_rqr_99, &r99a, by_rqr);
+
+
+
+
+
+
+
+struct req *cur;
+LIST_FOREACH(cur, &reqs_pri_global, by_pri)
+    printf("{%d %d} ", cur->pri, cur->rqr);
+printf("| ");
+LIST_FOREACH(cur, &reqs_rqr_42, by_rqr)
+    printf("{%d %d} ", cur->pri, cur->rqr);
+printf("| ");
+LIST_FOREACH(cur, &reqs_rqr_17, by_rqr)
+    printf("{%d %d} ", cur->pri, cur->rqr);
+printf("| ");
+LIST_FOREACH(cur, &reqs_rqr_99, by_rqr)
+    printf("{%d %d} ", cur->pri, cur->rqr);
+printf("\n");
+
+}
Index: doc/theses/mike_brooks_MMath/programs/lst-issues-wrapped-byref.run.cpp
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-issues-wrapped-byref.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-issues-wrapped-byref.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,58 @@
+#include <cstdio>
+
+#if defined INTERPOSED_LIST_NS
+using namespace INTERPOSED_LIST_NS;
+#else
+#include <list>
+using namespace std;
+#endif
+
+int main() {
+
+
+
+
+
+
+
+
+
+// C++
+
+struct req {
+  int pri, rqr;
+};
+
+
+
+
+list<req*> reqs;
+
+
+req
+  r1 = {1, 42},
+  r2 = {2, 42};
+
+reqs.push_front(
+  &r2);
+reqs.push_front(
+  &r1);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+for (auto const& cur : reqs)
+    printf("{%d %d} ", cur->pri, cur->rqr);
+printf("\n");
+
+}
Index: doc/theses/mike_brooks_MMath/programs/lst-issues-wrapped-emplaced.run.cpp
===================================================================
--- doc/theses/mike_brooks_MMath/programs/lst-issues-wrapped-emplaced.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
+++ doc/theses/mike_brooks_MMath/programs/lst-issues-wrapped-emplaced.run.cpp	(revision 57174958a53dde3bf79d4a2b102573e186836bdd)
@@ -0,0 +1,58 @@
+#include <cstdio>
+
+#if defined INTERPOSED_LIST_NS
+using namespace INTERPOSED_LIST_NS;
+#else
+#include <list>
+using namespace std;
+#endif
+
+int main() {
+
+
+
+
+
+
+
+
+
+// C++
+
+struct req {
+  int pri, rqr;
+};
+
+
+
+
+list<req> reqs;
+
+
+
+
+
+
+reqs.emplace_front(
+  2, 42);
+reqs.emplace_front(
+  1, 42);
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+for (auto const& cur : reqs)
+    printf("{%d %d} ", cur.pri, cur.rqr);
+printf("\n");
+
+}
