Browse Source

Initial commit of vectors library.
Contains a raw_vector<type, dim> type, and a BOOST_PP generated vector type system.

Samuel Jaffe 9 năm trước cách đây
commit
2cf49488e7

+ 78 - 0
Makefile

@@ -0,0 +1,78 @@
+WARNINGS := -Wall -pedantic  \
+  -pedantic-errors -Wextra -Wcast-align \
+  -Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion \
+  -Wdisabled-optimization \
+  -Werror -Wfloat-equal  -Wformat  -Wformat=2 \
+  -Wformat-nonliteral -Wformat-security  \
+  -Wformat-y2k \
+  -Wimport  -Winit-self  -Winline \
+  -Winvalid-pch   \
+  -Wunsafe-loop-optimizations  -Wno-long-long -Wmissing-braces \
+  -Wmissing-field-initializers -Wmissing-format-attribute   \
+  -Wmissing-include-dirs -Wmissing-noreturn -Wmissing-declarations \
+  -Wpacked -Wparentheses  -Wpointer-arith \
+  -Wredundant-decls -Wreturn-type \
+  -Wsequence-point  -Wshadow -Wsign-compare  -Wstack-protector \
+  -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default \
+  -Wswitch-enum -Wtrigraphs  -Wuninitialized \
+  -Wunknown-pragmas  -Wunreachable-code -Wunused \
+  -Wunused-function  -Wunused-label  -Wunused-parameter \
+  -Wunused-value  -Wunused-variable  -Wvariadic-macros \
+  -Wvolatile-register-var  -Wwrite-strings
+CWARNINGS := $(WARNINGS) -Wimplicit
+CPPWARNINGS := $(WARNINGS)
+
+CFLAGS   := $(CWARNINGS)
+CPPFLAGS := --std=c++11 $(CPPWARNINGS)
+LDFLAGS  :=
+
+HDRFILES := vector.hpp
+SRCFILES := 
+DEPFILES := $(patsubst %.cpp,.%.d,$(SRCFILES))
+OBJFILES := $(patsubst %.cpp,%.o,$(SRCFILES))
+TSTSUITE := vector_tc.h
+TSTFILES := $(patsubst %.h,%.cpp,$(TSTSUITE))
+TSTDRIVR := $(patsubst %.cpp,%,$(TSTFILES))
+BINARY   :=
+
+ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
+
+.PHONY: all clean debug release check coverage
+
+all: $(BINARY) $(LNBINARY)
+
+debug: CFLAGS += -DDEBUG -g
+debug: CPPFLAGS += -DDEBUG -g
+debug: all
+
+release: CFLAGS += -O2
+release: CPPFLAGS += -O2
+release: all
+
+coverage: CFLAGS += -fprofile-arcs -ftest-coverage
+coverage: CPPFLAGS += -fprofile-arcs -ftest-coverage
+coverage: check
+
+clean: check-clean
+	@$(RM) $(BINARY) $(wildcard $(OBJFILES)) $(LNBINARY)
+
+check-clean:
+	@$(RM) $(TSTDRIVR) $(TSTFILES)
+
+check: check-clean $(TSTDRIVR)
+
+.h.cpp:
+	@cxxtestgen --error-printer $< -o $@
+
+.cpp.o: Makefile
+	$(CXX) $(CPPFLAGS) -MMD -MP -MF $(patsubst %.cpp,.%.d,$<) -c $< -o $@
+
+$(BINARY): $(OBJFILES) 
+	$(CXX) $(LDFLAGS) -o $@ $(OBJFILES)
+
+$(TSTDRIVR): $(TSTFILES)
+	@$(CXX) $(CPPFLAGS) -I$(CXXTEST) -w $@.cpp -o $@
+	@echo Running TestDriver: ./$@
+	@./$@
+
+

+ 290 - 0
vector.hpp

@@ -0,0 +1,290 @@
+//
+//  vector.h
+//  
+//
+//  Created by Sam Jaffe on 8/21/15.
+//
+//
+
+#pragma once
+
+namespace math { namespace vector {
+  template <size_t, typename> class raw_vector;
+} }
+
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator +(T const&, math::vector::raw_vector<D, T> const&);
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator -(T const&, math::vector::raw_vector<D, T> const&);
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator *(T const&, math::vector::raw_vector<D, T> const&);
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator /(T const&, math::vector::raw_vector<D, T> const&);
+
+namespace math { namespace vector {
+  struct fill_t {} fill;
+
+  template <size_t D, typename T>
+  class raw_vector {
+  public:
+    typedef T value_type;
+    typedef T& reference;
+    typedef const T& const_reference;
+    typedef raw_vector<D, T> this_type;
+    
+    typedef decltype(std::sqrt(std::declval<T>())) sqrt_type; // double or float
+    
+    T& operator [](size_t index) { return data[index]; }
+    
+    inline const T& operator [](size_t index) const { return data[index]; }
+    
+    T& at(size_t index) {
+      if (index >= D) throw std::out_of_range(std::to_string(index) + " is out of range [0, " + std::to_string(D) + ")");
+      return operator [](index);
+    }
+    
+    const T& at(size_t index) const {
+      if (index >= D) throw std::out_of_range(std::to_string(index) + " is out of range [0, " + std::to_string(D) + ")");
+      return operator [](index);
+    }
+    
+    template <std::size_t Idx, typename = typename std::enable_if<Idx < D>::type>
+    inline const_reference get() const { return data[Idx]; }
+    
+    template <std::size_t Idx, typename = typename std::enable_if<Idx < D>::type>
+    inline reference get() { return data[Idx]; }
+    
+    reference x() { return get<0>(); }
+    const_reference x() const { return get<0>(); }
+    reference y() { return get<1>(); }
+    const_reference y() const { return get<1>(); }
+    reference z() { return get<2>(); }
+    const_reference z() const { return get<2>(); }
+    reference w() { return get<3>(); }
+    const_reference w() const { return get<3>(); }
+    reference r() { return get<0>(); }
+    const_reference r() const { return get<0>(); }
+    reference g() { return get<1>(); }
+    const_reference g() const { return get<1>(); }
+    reference b() { return get<2>(); }
+    const_reference b() const { return get<2>(); }
+    reference a() { return get<3>(); }
+    const_reference a() const { return get<3>(); }
+    
+    this_type& operator+=(const this_type& other) {
+      for (size_t i = 0; i < D; ++i) at(i) += other.at(i);
+      return *this;
+    }
+    
+    this_type& operator-=(const this_type& other) {
+      for (size_t i = 0; i < D; ++i) at(i) -= other.at(i);
+      return *this;
+    }
+    
+    this_type& operator*=(const this_type& other) {
+      for (size_t i = 0; i < D; ++i) at(i) *= other.at(i);
+      return *this;
+    }
+    
+    this_type& operator/=(const this_type& other) {
+      for (size_t i = 0; i < D; ++i) at(i) /= other.at(i);
+      return *this;
+    }
+    
+    this_type& operator+=(const T& c) {
+      return operator +=(this_type{c, fill});
+    }
+    
+    this_type& operator -=(const T& c) {
+      return operator -=(this_type{c, fill});
+    }
+    
+    this_type& operator *=(const T& c)  {
+      return operator *=(this_type{c, fill});
+    }
+    
+    this_type& operator /=(const T& c) {
+      return operator /=(this_type{c, fill});
+    }
+    
+    this_type operator +(const this_type& other) const {
+      return this_type(*this) += other;
+    }
+    
+    this_type operator -(const this_type& other) const {
+      return this_type(*this) -= other;
+    }
+    
+    this_type operator *(const this_type& other) const {
+      return this_type(*this) *= other;
+    }
+    
+    this_type operator /(const this_type& other) const {
+      return this_type(*this) /= other;
+    }
+    
+    this_type operator +(const T& c) const {
+      return operator +(this_type{c, fill});
+    }
+    
+    this_type operator -(const T& c) const {
+      return operator -(this_type{c, fill});
+    }
+    
+    this_type operator *(const T& c) const {
+      return operator *(this_type{c, fill});
+    }
+    
+    this_type operator /(const T& c) const {
+      return operator /(this_type{c, fill});
+    }
+    
+    this_type operator -() const { return -1 * (*this); }
+    
+    bool operator ==(const this_type& other) const {
+      return !memcmp(data, other.data, D * sizeof(T));
+    } // technically wrong on float/double
+    
+    bool operator !=(const this_type& other) const {
+      return !operator==(other);
+    }
+    
+    bool operator <=(const this_type& other) const {
+      for (size_t i = 0; i < D; ++i) { if (at(i) > other.at(i)) return false; }
+      return true;
+    }
+    
+    bool operator <(const this_type& other) const {
+      for (size_t i = 0; i < D; ++i) { if (at(i) >= other.at(i)) return false; }
+      return true;
+    }
+    
+    bool operator >=(const this_type& other) const {
+      for (size_t i = 0; i < D; ++i) { if (at(i) < other.at(i)) return false; }
+      return true;
+    }
+    
+    bool operator >(const this_type& other) const {
+      for (size_t i = 0; i < D; ++i) { if (at(i) <= other.at(i)) return false; }
+      return true;
+    }
+    
+    template <size_t D2>
+    typename std::enable_if<(D == 2 || D == 3) && D == D2, raw_vector<3, T> >::type cross(const raw_vector<D2, T>& v) const {
+      return D == 2
+      ? raw_vector<3, T>{0, 0, at(0)*v.at(1) - at(1)*v.at(0)}
+      : raw_vector<3, T>{
+        at(1)*v.at(2) - at(2)*v.at(1),
+        at(2)*v.at(0) - at(0)*v.at(2),
+        at(0)*v.at(1) - at(1)*v.at(0)
+      };
+    }
+    
+    T dot(const this_type& v) const {
+      T accum{};
+      for (size_t i = 0; i < D; ++i) accum += data[i] * v[i];
+      return accum;
+    }
+    
+    T lengthSquared() const {
+      return dot(*this);
+    }
+    
+    sqrt_type length() const {
+      return std::sqrt(lengthSquared());
+    }
+    
+    T distanceSquared(const this_type& other) const {
+      return operator -(other).lengthSquared();
+    }
+    
+    sqrt_type distance(const this_type& other) const {
+      return std::sqrt(distanceSquared(other));
+    }
+    
+    raw_vector<D, sqrt_type> unit() const { return raw_vector<D, sqrt_type>(*this)/length(); }
+    
+    void swap(raw_vector& that) {
+      using std::swap;
+      for (size_t i = 0; i < D; ++i) swap(data[i], that.data[i]);
+    }
+    
+    constexpr raw_vector() = default;
+    
+    raw_vector(const this_type& that) {
+      for (size_t i = 0; i < D; ++i) data[i] = that.data[i];
+    }
+    
+    raw_vector(this_type&& that) {
+      for (size_t i = 0; i < D; ++i) data[i] = that.data[i];
+    }
+    
+    raw_vector& operator=(const this_type& other) {
+      for (size_t i = 0; i < D; ++i) data[i] = other.data[i];
+      return *this;
+    }
+    
+    raw_vector& operator=(this_type&& other) {
+      for (size_t i = 0; i < D; ++i) data[i] = other.data[i];
+      return *this;
+    }
+    
+    raw_vector(std::initializer_list<T> vals) {
+      const size_t D2 = vals.size();
+      const T* ptr = vals.begin();
+      for (size_t i = 0; i < std::min(D, D2); ++i) data[i] = *ptr++;
+      for (size_t j = std::min(D, D2); j < std::max(D, D2); ++j) data[j] = T();
+    }
+    
+    template <std::size_t D2, typename T2,
+    typename = typename std::enable_if<D2 != D || !std::is_same<T, T2>::value>::type>
+    explicit raw_vector(const raw_vector<D2, T2>& that) {
+      for (size_t i = 0; i < std::min(D, D2); ++i) data[i] = static_cast<T>(that[i]);
+      for (size_t j = std::min(D, D2); j < std::max(D, D2); ++j) data[j] = T();
+    }
+    
+    raw_vector(T const& t, fill_t) {
+      for (size_t i = 0; i < D; ++i) data[i] = t;
+    }
+    
+  private:
+    value_type data[D] = {0};
+  };
+} }
+
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator +(T const& lhs, math::vector::raw_vector<D, T> const& rhs) {
+  return rhs + lhs;
+}
+
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator -(T const& lhs, math::vector::raw_vector<D, T> const& rhs) {
+  return math::vector::raw_vector<D, T>(lhs, math::vector::fill) - rhs;
+}
+
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator *(T const& lhs, math::vector::raw_vector<D, T> const& rhs) {
+  return rhs * lhs;
+}
+
+template <size_t D, typename T>
+math::vector::raw_vector<D, T> operator /(T const& lhs, math::vector::raw_vector<D, T> const& rhs) {
+  return math::vector::raw_vector<D, T>(lhs, math::vector::fill) / rhs;
+}
+
+template <typename CharT, typename Traits, size_t N, typename T>
+std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& out, const math::vector::raw_vector<N, T>& v) {
+  out << '(' << v[0];
+  for (size_t i = 1; i < N; ++i) { out << ',' << v[i]; }
+  out << ')';
+  return out;
+}
+
+namespace std {
+  template <size_t D, typename T>
+  math::vector::raw_vector<D, T> abs(math::vector::raw_vector<D, T> const& data) {
+    math::vector::raw_vector<D, T> rval;
+    for (size_t i = 0; i < D; ++i) rval[i] = std::abs(data[i]);
+    return rval;
+  }
+}

+ 302 - 0
vector.xcodeproj/project.pbxproj

@@ -0,0 +1,302 @@
+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 46;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		0E5DFDFB1BB4D5070063976E /* vector_tc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E5DFDDA1BB4D3360063976E /* vector_tc.cpp */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+		0E5DFDF11BB4D5040063976E /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 2147483647;
+			dstPath = /usr/share/man/man1/;
+			dstSubfolderSpec = 0;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 1;
+		};
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+		0E5DFDD71BB4D3360063976E /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
+		0E5DFDD81BB4D3360063976E /* vector.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = vector.hpp; sourceTree = "<group>"; };
+		0E5DFDDA1BB4D3360063976E /* vector_tc.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = vector_tc.cpp; sourceTree = "<group>"; };
+		0E5DFDDB1BB4D3360063976E /* vector_tc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = vector_tc.h; sourceTree = "<group>"; };
+		0E5DFDF31BB4D5040063976E /* vector_tc */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = vector_tc; sourceTree = BUILT_PRODUCTS_DIR; };
+		CD97B6211CA576B7007756C8 /* vector_type_generator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = vector_type_generator.hpp; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		0E5DFDF01BB4D5040063976E /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		0E5DFDD01BB4D3360063976E = {
+			isa = PBXGroup;
+			children = (
+				0E5DFDD71BB4D3360063976E /* Makefile */,
+				0E5DFDD81BB4D3360063976E /* vector.hpp */,
+				CD97B6211CA576B7007756C8 /* vector_type_generator.hpp */,
+				0E5DFDDA1BB4D3360063976E /* vector_tc.cpp */,
+				0E5DFDDB1BB4D3360063976E /* vector_tc.h */,
+				0E5DFDF41BB4D5040063976E /* Products */,
+			);
+			sourceTree = "<group>";
+		};
+		0E5DFDF41BB4D5040063976E /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				0E5DFDF31BB4D5040063976E /* vector_tc */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXLegacyTarget section */
+		0E5DFDD51BB4D3360063976E /* vector */ = {
+			isa = PBXLegacyTarget;
+			buildArgumentsString = "$(ACTION)";
+			buildConfigurationList = 0E5DFDDC1BB4D3360063976E /* Build configuration list for PBXLegacyTarget "vector" */;
+			buildPhases = (
+			);
+			buildToolPath = /usr/bin/make;
+			buildWorkingDirectory = "/Users/leumasjaffe/Documents/Programming/XTools Workspace/C:C++/misc/math/vector";
+			dependencies = (
+			);
+			name = vector;
+			passBuildSettingsInEnvironment = 1;
+			productName = vector;
+		};
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+		0E5DFDF21BB4D5040063976E /* vector_tc */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 0E5DFDF81BB4D5040063976E /* Build configuration list for PBXNativeTarget "vector_tc" */;
+			buildPhases = (
+				0E5DFDEF1BB4D5040063976E /* Sources */,
+				0E5DFDF01BB4D5040063976E /* Frameworks */,
+				0E5DFDF11BB4D5040063976E /* CopyFiles */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = vector_tc;
+			productName = vector_tc;
+			productReference = 0E5DFDF31BB4D5040063976E /* vector_tc */;
+			productType = "com.apple.product-type.tool";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		0E5DFDD11BB4D3360063976E /* Project object */ = {
+			isa = PBXProject;
+			attributes = {
+				LastUpgradeCheck = 0700;
+				TargetAttributes = {
+					0E5DFDF21BB4D5040063976E = {
+						CreatedOnToolsVersion = 7.0;
+					};
+				};
+			};
+			buildConfigurationList = 0E5DFDD41BB4D3360063976E /* Build configuration list for PBXProject "vector" */;
+			compatibilityVersion = "Xcode 3.2";
+			developmentRegion = English;
+			hasScannedForEncodings = 0;
+			knownRegions = (
+				en,
+			);
+			mainGroup = 0E5DFDD01BB4D3360063976E;
+			productRefGroup = 0E5DFDF41BB4D5040063976E /* Products */;
+			projectDirPath = "";
+			projectRoot = "";
+			targets = (
+				0E5DFDD51BB4D3360063976E /* vector */,
+				0E5DFDF21BB4D5040063976E /* vector_tc */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+		0E5DFDEF1BB4D5040063976E /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				0E5DFDFB1BB4D5070063976E /* vector_tc.cpp in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+		0E5DFDD21BB4D3360063976E /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+				ENABLE_TESTABILITY = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				ONLY_ACTIVE_ARCH = YES;
+				SDKROOT = macosx;
+			};
+			name = Debug;
+		};
+		0E5DFDD31BB4D3360063976E /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				SDKROOT = macosx;
+			};
+			name = Release;
+		};
+		0E5DFDDD1BB4D3360063976E /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+				DEBUGGING_SYMBOLS = YES;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = "";
+				PRODUCT_NAME = vector;
+			};
+			name = Debug;
+		};
+		0E5DFDDE1BB4D3360063976E /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				OTHER_CFLAGS = "";
+				OTHER_LDFLAGS = "";
+				PRODUCT_NAME = vector;
+			};
+			name = Release;
+		};
+		0E5DFDF91BB4D5040063976E /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_UNREACHABLE_CODE = YES;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				DEBUG_INFORMATION_FORMAT = dwarf;
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
+				ENABLE_TESTABILITY = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_NO_COMMON_BLOCKS = YES;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"DEBUG=1",
+					"$(inherited)",
+				);
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				HEADER_SEARCH_PATHS = "${HOME}/Documents/Programming/cxxtest-4.4/";
+				MACOSX_DEPLOYMENT_TARGET = 10.10;
+				MTL_ENABLE_DEBUG_INFO = YES;
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				SDKROOT = macosx;
+			};
+			name = Debug;
+		};
+		0E5DFDFA1BB4D5040063976E /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN_UNREACHABLE_CODE = YES;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				COPY_PHASE_STRIP = NO;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				ENABLE_NS_ASSERTIONS = NO;
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_NO_COMMON_BLOCKS = YES;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				HEADER_SEARCH_PATHS = "${HOME}/Documents/Programming/cxxtest-4.4/";
+				MACOSX_DEPLOYMENT_TARGET = 10.10;
+				MTL_ENABLE_DEBUG_INFO = NO;
+				PRODUCT_NAME = "$(TARGET_NAME)";
+				SDKROOT = macosx;
+			};
+			name = Release;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		0E5DFDD41BB4D3360063976E /* Build configuration list for PBXProject "vector" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				0E5DFDD21BB4D3360063976E /* Debug */,
+				0E5DFDD31BB4D3360063976E /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		0E5DFDDC1BB4D3360063976E /* Build configuration list for PBXLegacyTarget "vector" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				0E5DFDDD1BB4D3360063976E /* Debug */,
+				0E5DFDDE1BB4D3360063976E /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		0E5DFDF81BB4D5040063976E /* Build configuration list for PBXNativeTarget "vector_tc" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				0E5DFDF91BB4D5040063976E /* Debug */,
+				0E5DFDFA1BB4D5040063976E /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+/* End XCConfigurationList section */
+	};
+	rootObject = 0E5DFDD11BB4D3360063976E /* Project object */;
+}

+ 80 - 0
vector.xcodeproj/xcuserdata/leumasjaffe.xcuserdatad/xcschemes/vector.xcscheme

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0700"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "0E5DFDD51BB4D3360063976E"
+               BuildableName = "vector"
+               BlueprintName = "vector"
+               ReferencedContainer = "container:vector.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+      </Testables>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDD51BB4D3360063976E"
+            BuildableName = "vector"
+            BlueprintName = "vector"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDD51BB4D3360063976E"
+            BuildableName = "vector"
+            BlueprintName = "vector"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 91 - 0
vector.xcodeproj/xcuserdata/leumasjaffe.xcuserdatad/xcschemes/vector_tc.xcscheme

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0700"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+               BuildableName = "vector_tc"
+               BlueprintName = "vector_tc"
+               ReferencedContainer = "container:vector.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+      </Testables>
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+            BuildableName = "vector_tc"
+            BlueprintName = "vector_tc"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+            BuildableName = "vector_tc"
+            BlueprintName = "vector_tc"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+            BuildableName = "vector_tc"
+            BlueprintName = "vector_tc"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 32 - 0
vector.xcodeproj/xcuserdata/leumasjaffe.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>SchemeUserState</key>
+	<dict>
+		<key>vector.xcscheme</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>4</integer>
+		</dict>
+		<key>vector_tc.xcscheme</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>5</integer>
+		</dict>
+	</dict>
+	<key>SuppressBuildableAutocreation</key>
+	<dict>
+		<key>0E5DFDD51BB4D3360063976E</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
+		<key>0E5DFDF21BB4D5040063976E</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
+	</dict>
+</dict>
+</plist>

+ 80 - 0
vector.xcodeproj/xcuserdata/samjaffe.xcuserdatad/xcschemes/vector.xcscheme

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0720"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "0E5DFDD51BB4D3360063976E"
+               BuildableName = "vector"
+               BlueprintName = "vector"
+               ReferencedContainer = "container:vector.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+      </Testables>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDD51BB4D3360063976E"
+            BuildableName = "vector"
+            BlueprintName = "vector"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDD51BB4D3360063976E"
+            BuildableName = "vector"
+            BlueprintName = "vector"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 91 - 0
vector.xcodeproj/xcuserdata/samjaffe.xcuserdatad/xcschemes/vector_tc.xcscheme

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0720"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+               BuildableName = "vector_tc"
+               BlueprintName = "vector_tc"
+               ReferencedContainer = "container:vector.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES">
+      <Testables>
+      </Testables>
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+            BuildableName = "vector_tc"
+            BlueprintName = "vector_tc"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </TestAction>
+   <LaunchAction
+      buildConfiguration = "Debug"
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      debugServiceExtension = "internal"
+      allowLocationSimulation = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+            BuildableName = "vector_tc"
+            BlueprintName = "vector_tc"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      buildConfiguration = "Release"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      debugDocumentVersioning = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "0E5DFDF21BB4D5040063976E"
+            BuildableName = "vector_tc"
+            BlueprintName = "vector_tc"
+            ReferencedContainer = "container:vector.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>

+ 32 - 0
vector.xcodeproj/xcuserdata/samjaffe.xcuserdatad/xcschemes/xcschememanagement.plist

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>SchemeUserState</key>
+	<dict>
+		<key>vector.xcscheme</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>2</integer>
+		</dict>
+		<key>vector_tc.xcscheme</key>
+		<dict>
+			<key>orderHint</key>
+			<integer>3</integer>
+		</dict>
+	</dict>
+	<key>SuppressBuildableAutocreation</key>
+	<dict>
+		<key>0E5DFDD51BB4D3360063976E</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
+		<key>0E5DFDF21BB4D5040063976E</key>
+		<dict>
+			<key>primary</key>
+			<true/>
+		</dict>
+	</dict>
+</dict>
+</plist>

+ 200 - 0
vector_tc.cpp

@@ -0,0 +1,200 @@
+/* Generated file, do not edit */
+
+#ifndef CXXTEST_RUNNING
+#define CXXTEST_RUNNING
+#endif
+
+#define _CXXTEST_HAVE_STD
+#define _CXXTEST_HAVE_EH
+#include <cxxtest/TestListener.h>
+#include <cxxtest/TestTracker.h>
+#include <cxxtest/TestRunner.h>
+#include <cxxtest/RealDescriptions.h>
+#include <cxxtest/TestMain.h>
+#include <cxxtest/ErrorPrinter.h>
+
+int main( int argc, char *argv[] ) {
+ int status;
+    CxxTest::ErrorPrinter tmp;
+    CxxTest::RealWorldDescription::_worldName = "cxxtest";
+    status = CxxTest::Main< CxxTest::ErrorPrinter >( tmp, argc, argv );
+    return status;
+}
+bool suite_vector_TestSuite_init = false;
+#include "vector_tc.h"
+
+static vector_TestSuite suite_vector_TestSuite;
+
+static CxxTest::List Tests_vector_TestSuite = { 0, 0 };
+CxxTest::StaticSuiteDescription suiteDescription_vector_TestSuite( "vector_tc.h", 5, "vector_TestSuite", suite_vector_TestSuite, Tests_vector_TestSuite );
+
+static class TestDescription_suite_vector_TestSuite_test_vector_equals : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_equals() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 12, "test_vector_equals" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_equals(); }
+} testDescription_suite_vector_TestSuite_test_vector_equals;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_notequals : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_notequals() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 16, "test_vector_notequals" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_notequals(); }
+} testDescription_suite_vector_TestSuite_test_vector_notequals;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_elems : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_elems() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 20, "test_vector_elems" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_elems(); }
+} testDescription_suite_vector_TestSuite_test_vector_elems;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_oob : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_oob() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 27, "test_vector_oob" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_oob(); }
+} testDescription_suite_vector_TestSuite_test_vector_oob;
+
+static class TestDescription_suite_vector_TestSuite_test_default_zero : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_default_zero() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 31, "test_default_zero" ) {}
+ void runTest() { suite_vector_TestSuite.test_default_zero(); }
+} testDescription_suite_vector_TestSuite_test_default_zero;
+
+static class TestDescription_suite_vector_TestSuite_test_extends_with_zero : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_extends_with_zero() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 35, "test_extends_with_zero" ) {}
+ void runTest() { suite_vector_TestSuite.test_extends_with_zero(); }
+} testDescription_suite_vector_TestSuite_test_extends_with_zero;
+
+static class TestDescription_suite_vector_TestSuite_test_vec2_cross : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vec2_cross() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 39, "test_vec2_cross" ) {}
+ void runTest() { suite_vector_TestSuite.test_vec2_cross(); }
+} testDescription_suite_vector_TestSuite_test_vec2_cross;
+
+static class TestDescription_suite_vector_TestSuite_test_vec3_cross : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vec3_cross() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 43, "test_vec3_cross" ) {}
+ void runTest() { suite_vector_TestSuite.test_vec3_cross(); }
+} testDescription_suite_vector_TestSuite_test_vec3_cross;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_addition_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_addition_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 47, "test_vector_addition_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_addition_vector(); }
+} testDescription_suite_vector_TestSuite_test_vector_addition_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_subtraction_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_subtraction_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 51, "test_vector_subtraction_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_subtraction_vector(); }
+} testDescription_suite_vector_TestSuite_test_vector_subtraction_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_multiplication_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_multiplication_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 55, "test_vector_multiplication_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_multiplication_vector(); }
+} testDescription_suite_vector_TestSuite_test_vector_multiplication_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_divides_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_divides_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 59, "test_vector_divides_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_divides_vector(); }
+} testDescription_suite_vector_TestSuite_test_vector_divides_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_addition_value : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_addition_value() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 63, "test_vector_addition_value" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_addition_value(); }
+} testDescription_suite_vector_TestSuite_test_vector_addition_value;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_subtraction_value : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_subtraction_value() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 67, "test_vector_subtraction_value" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_subtraction_value(); }
+} testDescription_suite_vector_TestSuite_test_vector_subtraction_value;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_multiplication_value : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_multiplication_value() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 71, "test_vector_multiplication_value" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_multiplication_value(); }
+} testDescription_suite_vector_TestSuite_test_vector_multiplication_value;
+
+static class TestDescription_suite_vector_TestSuite_test_vector_divides_value : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_vector_divides_value() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 75, "test_vector_divides_value" ) {}
+ void runTest() { suite_vector_TestSuite.test_vector_divides_value(); }
+} testDescription_suite_vector_TestSuite_test_vector_divides_value;
+
+static class TestDescription_suite_vector_TestSuite_test_value_addition_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_value_addition_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 79, "test_value_addition_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_value_addition_vector(); }
+} testDescription_suite_vector_TestSuite_test_value_addition_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_value_subtraction_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_value_subtraction_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 83, "test_value_subtraction_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_value_subtraction_vector(); }
+} testDescription_suite_vector_TestSuite_test_value_subtraction_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_value_multiplication_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_value_multiplication_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 87, "test_value_multiplication_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_value_multiplication_vector(); }
+} testDescription_suite_vector_TestSuite_test_value_multiplication_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_value_divides_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_value_divides_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 91, "test_value_divides_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_value_divides_vector(); }
+} testDescription_suite_vector_TestSuite_test_value_divides_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_length_of_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_length_of_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 95, "test_length_of_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_length_of_vector(); }
+} testDescription_suite_vector_TestSuite_test_length_of_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_distance_of_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_distance_of_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 100, "test_distance_of_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_distance_of_vector(); }
+} testDescription_suite_vector_TestSuite_test_distance_of_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_dot_product : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_dot_product() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 105, "test_dot_product" ) {}
+ void runTest() { suite_vector_TestSuite.test_dot_product(); }
+} testDescription_suite_vector_TestSuite_test_dot_product;
+
+static class TestDescription_suite_vector_TestSuite_test_unit_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_unit_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 109, "test_unit_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_unit_vector(); }
+} testDescription_suite_vector_TestSuite_test_unit_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_type_shift : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_type_shift() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 115, "test_type_shift" ) {}
+ void runTest() { suite_vector_TestSuite.test_type_shift(); }
+} testDescription_suite_vector_TestSuite_test_type_shift;
+
+static class TestDescription_suite_vector_TestSuite_test_swap : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_swap() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 119, "test_swap" ) {}
+ void runTest() { suite_vector_TestSuite.test_swap(); }
+} testDescription_suite_vector_TestSuite_test_swap;
+
+static class TestDescription_suite_vector_TestSuite_test_negate_vector : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_negate_vector() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 127, "test_negate_vector" ) {}
+ void runTest() { suite_vector_TestSuite.test_negate_vector(); }
+} testDescription_suite_vector_TestSuite_test_negate_vector;
+
+static class TestDescription_suite_vector_TestSuite_test_absolute_value : public CxxTest::RealTestDescription {
+public:
+ TestDescription_suite_vector_TestSuite_test_absolute_value() : CxxTest::RealTestDescription( Tests_vector_TestSuite, suiteDescription_vector_TestSuite, 131, "test_absolute_value" ) {}
+ void runTest() { suite_vector_TestSuite.test_absolute_value(); }
+} testDescription_suite_vector_TestSuite_test_absolute_value;
+
+#include <cxxtest/Root.cpp>
+const char* CxxTest::RealWorldDescription::_worldName = "cxxtest";

+ 145 - 0
vector_tc.h

@@ -0,0 +1,145 @@
+#include <cxxtest/TestSuite.h>
+
+#include "vector.hpp"
+
+class vector_TestSuite : public CxxTest::TestSuite {
+public:
+  using vec2i = math::vector::raw_vector<2, int>;
+  using vec3  = math::vector::raw_vector<3, double>;
+  using vec3i = math::vector::raw_vector<3, int>;
+  using vec4i = math::vector::raw_vector<4, int>;
+
+  void test_vector_equals() const {
+    TS_ASSERT_EQUALS(iota3i(), (vec3i{1, 2, 3}));
+  }
+  
+  void test_vector_notequals() const {
+    TS_ASSERT_DIFFERS(iota3i(), (vec3i{0, 2, 3}));
+  }
+  
+  void test_vector_elems() const {
+    math::vector::raw_vector<3, int> viota = iota3i();
+    TS_ASSERT_EQUALS(viota[0], 1);
+    TS_ASSERT_EQUALS(viota[1], 2);
+    TS_ASSERT_EQUALS(viota[2], 3);
+  }
+  
+  void test_vector_oob() const {
+    TS_ASSERT_THROWS((iota<3, int>()).at(3), std::out_of_range);
+  }
+  
+  void test_default_zero() const {
+    TS_ASSERT_EQUALS(vec3i(), (vec3i{0,0,0}));
+  }
+  
+  void test_extends_with_zero() const {
+    TS_ASSERT_EQUALS(vec4i(iota3i()), (vec4i{1,2,3,0}));
+  }
+  
+  void test_vec2_cross() const {
+    TS_ASSERT_EQUALS((vec2i{1,1}.cross(vec2i{-1,1})), (vec3i{0,0,2}));
+  }
+  
+  void test_vec3_cross() const {
+    TS_ASSERT_EQUALS((vec3i{1,1,2}.cross(vec3i{-1,1,1})), (vec3i{-1,-3,2}));
+  }
+  
+  void test_vector_addition_vector() const {
+    TS_ASSERT_EQUALS((vec2i{1,0} + vec2i{0,1}), (vec2i{1,1}))
+  }
+  
+  void test_vector_subtraction_vector() const {
+    TS_ASSERT_EQUALS((vec2i{1,0} - vec2i{0,1}), (vec2i{1,-1}))
+  }
+  
+  void test_vector_multiplication_vector() const {
+    TS_ASSERT_EQUALS((vec2i{1,0} * vec2i{2,1}), (vec2i{2,0}))
+  }
+  
+  void test_vector_divides_vector() const {
+    TS_ASSERT_EQUALS((vec2i{6,4} / vec2i{2,1}), (vec2i{3,4}))
+  }
+  
+  void test_vector_addition_value() const {
+    TS_ASSERT_EQUALS((vec2i{1,0} + 1), (vec2i{2,1}))
+  }
+  
+  void test_vector_subtraction_value() const {
+    TS_ASSERT_EQUALS((vec2i{1,0} - 1), (vec2i{0,-1}))
+  }
+  
+  void test_vector_multiplication_value() const {
+    TS_ASSERT_EQUALS((vec2i{1,0} * 3), (vec2i{3,0}))
+  }
+  
+  void test_vector_divides_value() const {
+    TS_ASSERT_EQUALS((vec2i{6,4} / 2), (vec2i{3,2}))
+  }
+  
+  void test_value_addition_vector() const {
+    TS_ASSERT_EQUALS(1+iota2i(), (vec2i{2,3}));
+  }
+  
+  void test_value_subtraction_vector() const {
+    TS_ASSERT_EQUALS(4-iota2i(), (vec2i{3,2}));
+  }
+  
+  void test_value_multiplication_vector() const {
+    TS_ASSERT_EQUALS(2*iota2i(), (vec2i{2,4}));
+  }
+  
+  void test_value_divides_vector() const {
+    TS_ASSERT_EQUALS(4/iota2i(), (vec2i{4,2}));
+  }
+  
+  void test_length_of_vector() const {
+    TS_ASSERT_EQUALS(iota3i().lengthSquared(), 14);
+    TS_ASSERT_DELTA(iota3i().length(), std::sqrt(14), 0.00001);
+  }
+  
+  void test_distance_of_vector() const {
+    TS_ASSERT_EQUALS((iota3i().distanceSquared(vec3i{3, 1, -1})), 21);
+    TS_ASSERT_DELTA((iota3i().distance(vec3i{3, 1, -1})), std::sqrt(21), 0.00001);
+  }
+  
+  void test_dot_product() const {
+    TS_ASSERT_EQUALS((iota3i().dot(vec3i{3, 0, -1})), 0);
+  }
+  
+  void test_unit_vector() const {
+    double sq = std::sqrt(14);
+    vec3 epsilon{0.00001, math::vector::fill};
+    TS_ASSERT_DELTA(iota3i().unit(), (vec3{1/sq, 2/sq, 3/sq}), epsilon);
+  }
+  
+  void test_type_shift() const {
+    TS_ASSERT_EQUALS((vec3i(vec3{1.0, 2.3, 3.9})), iota3i());
+  }
+  
+  void test_swap() const {
+    vec2i a{1, 2}; const vec2i ac = a;
+    vec2i b{5, 7}; const vec2i bc = b;
+    a.swap(b);
+    TS_ASSERT_EQUALS(a, bc);
+    TS_ASSERT_EQUALS(b, ac);
+  }
+  
+  void test_negate_vector() const {
+    TS_ASSERT_EQUALS(-iota3i(), (vec3i{-1,-2,-3}));
+  }
+  
+  void test_absolute_value() const {
+    TS_ASSERT_EQUALS(iota3i(), std::abs(-iota3i()));
+  }
+  
+private:
+  
+  template <size_t N, typename T> math::vector::raw_vector<N, T> iota() const {
+    math::vector::raw_vector<N, T> rval;
+    for (size_t i = 0; i < N; ++i) rval[i] = static_cast<T>(i+1);
+    return rval;
+  }
+  
+  vec2i iota2i() const { return iota<2, int>(); }
+  vec3i iota3i() const { return iota<3, int>(); }
+};

+ 63 - 0
vector_type_generator.hpp

@@ -0,0 +1,63 @@
+#include <boost/preprocessor/seq/for_each.hpp>
+
+#include <boost/preprocessor/tuple/elem.hpp>
+
+#include <boost/preprocessor/seq/size.hpp>
+#include <boost/preprocessor/seq/to_tuple.hpp>
+#include <boost/preprocessor/tuple/to_list.hpp>
+#include <boost/preprocessor/list/for_each.hpp>
+
+#define APPLY_BINARY_OPERATOR(z, op, field)\
+  lhs.field op rhs.field;
+
+#define DEFINE_BINARY_OPERATOR(left_t, right_t, op, fields)\
+  left_t& operator op##=(left_t && lhs, right_t const& rhs) {\
+    BOOST_PP_SEQ_FOR_EACH(APPLY_BINARY_OPERATOR, op##=, fields)\
+    return lhs;\
+  }\
+  left_t operator op(left_t const& lhs, right_t const& rhs) {\
+    return left_t{lhs} op##= rhs;\
+  }
+
+#define DEFINE_SELF_BINARY_OPERATOR(type, op, fields)\
+  DEFINE_BINARY_OPERATOR(type, type, op, fields)
+
+#define DEFINE_VECTOR_MEMVAR(z, type, field)\
+  type field;
+
+#define DEFINE_VECTOR_OPERATOR2(type, op, fields)\
+DEFINE_SELF_BINARY_OPERATOR(type, op, fields)
+
+#define DEFINE_VECTOR_OPERATOR(z, tup, op)\
+  DEFINE_VECTOR_OPERATOR2(BOOST_PP_TUPLE_ELEM(2, 0, tup), op, BOOST_PP_TUPLE_ELEM(2, 1, tup))
+
+// We convert to a list because recursive calls to BOOST_PP_SEQ_FOR_EACH don't work
+#define MAKE_VECTOR_TYPE(type, elem_t, fields, operators)\
+  struct type {\
+    BOOST_PP_SEQ_FOR_EACH(DEFINE_VECTOR_MEMVAR, elem_t, fields)\
+  };\
+  BOOST_PP_LIST_FOR_EACH(DEFINE_VECTOR_OPERATOR, (type, fields), BOOST_PP_TUPLE_TO_LIST(BOOST_PP_SEQ_SIZE(operators), BOOST_PP_SEQ_TO_TUPLE(operators)))
+
+#define VECTOR_XY   (x)(y)
+#define VECTOR_XYZ  (x)(y)(z)
+#define VECTOR_XYZW (x)(y)(z)(w)
+#define VECTOR_RGBA (r)(g)(b)(a)
+
+#define OP_ADD             (+)
+#define OP_ADD_SUB         (+)(-)
+#define OP_ADD_MUL         (+)   (*)
+#define OP_ADD_SUB_MUL     (+)(-)(*)
+#define OP_ADD_SUB_MUL_DIV (+)(-)(*)(/)
+
+//#ifdef MANUAL_STRUCT
+//struct Position2d {
+//  unsigned int x;
+//  unsigned int y;
+//};
+//
+//DEFINE_SELF_BINARY_OPERATOR(Position2d, +, (x)(y))
+//#else
+//MAKE_VECTOR_TYPE(Position2d, unsigned int, VECTOR_XY, OP_ADD)
+//MAKE_VECTOR_TYPE(Offset2d, signed int, VECTOR_XY, OP_ADD)
+//DEFINE_BINARY_OPERATOR(Position2d, Offset2d, +, VECTOR_XY)
+//#endif