Index: src/Tesselation/TriangleMatcher/Makefile.am
===================================================================
--- src/Tesselation/TriangleMatcher/Makefile.am	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
+++ src/Tesselation/TriangleMatcher/Makefile.am	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
@@ -0,0 +1,33 @@
+# PLEASE adhere to the alphabetical ordering in this Makefile!
+# Also indentation by a single tab
+
+MOSTLYCLEANFILES =
+lib_LTLIBRARIES =
+noinst_LTLIBRARIES =
+pyexec_LTLIBRARIES =
+BUILT_SOURCES =
+bin_PROGRAMS =
+EXTRA_DIST =
+
+AM_LDFLAGS = -ldl ${BOOST_LDFLAGS} ${CodePatterns_LDFLAGS}
+AM_CPPFLAGS = \
+	${BOOST_CPPFLAGS} \
+	${CodePatterns_CFLAGS}
+
+bin_PROGRAMS += \
+	trianglematcher
+
+trianglematcher_SOURCES = \
+	Triangle.hpp \
+	types.hpp \
+	TriangleMatcher.cpp
+trianglematcher_CPPFLAGS = \
+	$(AM_CPPFLAGS) \
+	-std=c++0x
+trianglematcher_LDFLAGS = \
+	$(AM_LDFLAGS) \
+	$(BOOST_FILESYSTEM_LDFLAGS) \
+	$(BOOST_SYSTEM_LDFLAGS)
+trianglematcher_LDADD = \
+	$(BOOST_FILESYSTEM_LIBS) \
+	$(BOOST_SYSTEM_LIBS)	
Index: src/Tesselation/TriangleMatcher/Triangle.hpp
===================================================================
--- src/Tesselation/TriangleMatcher/Triangle.hpp	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
+++ src/Tesselation/TriangleMatcher/Triangle.hpp	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
@@ -0,0 +1,145 @@
+/*
+ * Triangle.hpp
+ *
+ *  Created on: Jun 15, 2015
+ *      Author: heber
+ */
+
+#ifndef TRIANGLE_HPP_
+#define TRIANGLE_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <array>
+#include <cassert>
+#include <utility>
+
+#include "types.hpp"
+
+namespace detail {
+
+struct Triangle
+{
+	//!> typedef for the triangle index type
+	typedef size_t index_t;
+
+	//!> typedef for the structure to store triangle indices
+	typedef std::array<index_t, 3> indices_t;
+
+	//!> constant for invalid index
+	enum { INVALIDINDEX=-1 };
+
+	/** Constructor for struct triangle.
+	 *
+	 */
+	Triangle()
+	{
+		indices = {{
+				(index_t)INVALIDINDEX,
+				(index_t)INVALIDINDEX,
+				(index_t)INVALIDINDEX
+		}};
+	}
+
+	/** Constructor for struct triangle.
+	 *
+	 * \param _indices initial indices to set
+	 */
+	Triangle(const indices_t &_indices) :
+		indices(_indices)
+	{
+		if (!isSorted())
+			sortIndices();
+	}
+
+	/** Setter for the indices of the triangle.
+	 *
+	 * \param _elements indices to be set (need not be sorted)
+	 */
+	void set(const indices_t &_elements) {
+		indices = _elements;
+		if (!isSorted())
+			sortIndices();
+	}
+
+	/** Getter for the indices.
+	 *
+	 * \return set of sorted indices
+	 */
+	const indices_t &get() const {
+		return indices;
+	}
+
+	/** Less comparator for triangle, comparing indices.
+	 *
+	 * \return true - at least one index in this triangle is smaller
+	 */
+	bool operator<(const Triangle &_other) const {
+		return indices < _other.indices;
+	}
+
+	/** Comparator for equivalence of triangle.
+	 *
+	 * \return true - both index triples are the same
+	 */
+	bool operator==(const Triangle &_other) const {
+		return indices == _other.indices;
+	}
+
+	/** Comparator for non-equivalence of triangle.
+	 *
+	 * \return true - both index triples are not the same
+	 */
+	bool operator!=(const Triangle &_other) const {
+		return !(*this == _other);
+	}
+
+private:
+	/** Sort the indices.
+	 *
+	 */
+	void sortIndices() {
+		std::sort(indices.begin(), indices.end());
+//		if (indices[0] > indices[1]) {
+//			if (indices[0] > indices[2])
+//				std::swap(indices[0], indices[2]);
+//			if (indices[0] > indices[1])
+//				std::swap(indices[0], indices[1]);
+//		} else {
+//			// last element in between or up front?
+//			if (indices[0] > indices[2]) {
+//				std::swap(indices[1], indices[2]);
+//				std::swap(indices[0], indices[1]);
+//			} else
+//				std::swap(indices[1], indices[2]);
+//		}
+		assert( isSorted() );
+	}
+
+private:
+	/** Check whether indices are sorted.
+	 *
+	 * \return true - indices are sorted ascendingly
+	 */
+	bool isSorted() const
+	{
+		return (( indices[0] <= indices[1]) && (indices[1] <= indices[2]));
+	}
+
+private:
+	//!> fixed size array for containing indices
+	indices_t indices;
+};
+
+}; /* namespace detail */
+
+std::ostream& operator<<(std::ostream &_ost, const detail::Triangle &_t) {
+	const detail::Triangle::indices_t &indices = _t.get();
+	_ost << "[" << indices[0] << ","  << indices[1] << "," << indices[2] << "]";
+	return _ost;
+}
+
+#endif /* TRIANGLE_HPP_ */
Index: src/Tesselation/TriangleMatcher/TriangleMatcher.cpp
===================================================================
--- src/Tesselation/TriangleMatcher/TriangleMatcher.cpp	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
+++ src/Tesselation/TriangleMatcher/TriangleMatcher.cpp	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
@@ -0,0 +1,203 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2015 Frederik Heber. All rights reserved.
+ *
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * TriangleMatcher.cpp
+ *
+ *  Created on: Jun 15, 2016
+ *      Author: heber
+ *
+ *
+ *  This is a small study in C++11 that compares at least two
+ *  files containing the triangle index triples of tesselations
+ *  for equivalence
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include <boost/exception/all.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/tokenizer.hpp>
+
+#include <algorithm>
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <sstream>
+#include <string>
+#include <map>
+
+#include "types.hpp"
+
+using namespace detail;
+
+namespace bf = boost::filesystem;
+
+typedef boost::error_info<
+		struct tag_IllegalTesselationFileContent_LineNumber,
+		int> IllegalTesselationFileContent_LineNumber;
+
+typedef boost::error_info<
+		struct tag_IllegalTesselationFileContent_Entries,
+		int> IllegalTesselationFileContent_Entries;
+
+typedef boost::error_info<
+		struct tag_IllegalTesselationFileContent_Line,
+		int> IllegalTesselationFileContent_Line;
+
+//!> Exception for illegal lines encountered in tesselation files
+struct IllegalTesselationFileContentException:
+		virtual boost::exception, virtual std::exception { };
+
+Triangle::index_t toIndex(const std::string &_element)
+{
+	Triangle::index_t index;
+	std::stringstream tokenstring(_element);
+	tokenstring >> index;
+	return index;
+}
+
+template <class T>
+std::ostream& operator<<(
+		std::ostream &_ost,
+		const std::set<T> &elements)
+{
+	for( const T elem : elements)
+		_ost << elem << std::endl;
+	return _ost;
+}
+
+/** Parses a tesselation file into a vector of Triangles.
+ *
+ * \param _filename name of file to parse
+ * \return tesselation_t structure filled with triangle index triples
+ */
+const tesselation_t parseFile(const boost::filesystem::path &_filename)
+{
+	tesselation_t tesselation;
+
+	std::ifstream infile(_filename.string().c_str());
+	boost::char_separator<char> sep(" \t");
+
+	typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+	std::string line;
+	int line_number = 1;
+	// read up till encountering an empty line
+	while (!infile.eof()) {
+		std::getline(infile, line);
+		if (line.empty())
+			break;
+	}
+	while (!infile.eof()) {
+		std::getline(infile, line);
+		tokenizer tokens(line, sep);
+		Triangle::indices_t indices;
+		const int entries = std::distance( tokens.begin(), tokens.end() );
+		// check for empty lines
+		if (entries == 0)
+			continue;
+		// entries must be exactly three if any
+		if ( entries !=  NUMBERINDICESTRIANGLE )
+			throw IllegalTesselationFileContentException()
+				<< IllegalTesselationFileContent_LineNumber(line_number)
+				<< IllegalTesselationFileContent_Entries(entries);
+		std::transform(
+				tokens.begin(),
+				tokens.end(),
+				indices.begin(),
+				toIndex);
+		tesselation.insert(Triangle(indices));
+
+		++line_number;
+	}
+	infile.close();
+
+	return tesselation;
+}
+
+int main(int argc, char **argv) {
+
+	/// check arguments and give usage
+	if (argc <= 2) {
+		std::cerr << "Usage: " << argv[0] << " <list of files>\n";
+		std::cerr << "At least two tesselation files need to be specified that contain\n";
+		std::cerr << "each three indices per line.\n";
+
+		return 255;
+	}
+
+	/// read in files and parse into structures
+	typedef std::multimap<tesselation_t, std::string> tesselations_filename_t;
+	//!> contains all tesselations parsed from files
+	tesselations_filename_t tesselations;
+	for (int i=1; i<argc;++i) {
+		const bf::path filename(argv[i]);
+		if (bf::exists(filename)) {
+			try {
+				tesselation_t tesselation = parseFile(filename);
+				tesselations.insert(
+						std::make_pair(tesselation, filename.string()) );
+			} catch (IllegalTesselationFileContentException &e) {
+				std::cerr << "Illegal line at "
+						<< *boost::get_error_info<IllegalTesselationFileContent_LineNumber>(e)
+						<< " encountered with "
+						<< *boost::get_error_info<IllegalTesselationFileContent_Entries>(e)
+						<< " entries in "
+						<< filename.string()
+						<< ", aborting.\n";
+				return 5;
+			}
+		} else {
+			std::cerr << "The following file does not exist "
+					<< filename.string() << ", aborting.\n";
+			return 5;
+		}
+	}
+
+	/// make comparison for equivalence
+	assert( tesselations.size() >= 2 );
+	tesselations_filename_t::const_iterator advancer = tesselations.begin();
+	tesselations_filename_t::const_iterator iter = advancer++;
+
+	bool AllEqual = true;
+	while( advancer != tesselations.end() ) {
+		if (advancer->first == iter->first) {
+			std::cout << "MATCH: "
+					<< advancer->second << " and " << iter->second
+					<< std::endl;
+		} else {
+			std::cout << advancer->first << " and " << iter->first
+					<< " don't match.\n";
+			AllEqual = false;
+		}
+		iter = advancer++;
+	}
+
+	// exit (convert bool to int)
+	return (AllEqual ? 0 : 1);
+}
Index: src/Tesselation/TriangleMatcher/types.hpp
===================================================================
--- src/Tesselation/TriangleMatcher/types.hpp	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
+++ src/Tesselation/TriangleMatcher/types.hpp	(revision 7d146a387231de6a2198a250dbdbab1f1e9076bd)
@@ -0,0 +1,30 @@
+/*
+ * types.hpp
+ *
+ *  Created on: Jun 15, 2015
+ *      Author: heber
+ */
+
+#ifndef TRIANGLEMATCHER_TYPES_HPP_
+#define TRIANGLEMATCHER_TYPES_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <set>
+
+#include "Triangle.hpp"
+
+//!> constant for number of indices in triangle
+#define NUMBERINDICESTRIANGLE 3
+
+namespace detail {
+
+	//!> typedef for a vector of triangles, i.e. contents of a a tesselation file
+	typedef std::set<Triangle> tesselation_t;
+
+}; /* namespace detail */
+
+#endif /* TRIANGLEMATCHER_TYPES_HPP_ */
