From ded124a95514c063fb6ec99830aca849d1f7cd71 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 14 Jun 2018 13:41:36 +0200
Subject: [PATCH] drop container features

---
 alib2common/src/common/createUnique.hpp       |  2 +-
 alib2common/src/container/ContainerFeatures.h | 44 -------------------
 alib2common/src/container/ObjectsDeque.h      |  3 +-
 alib2common/src/container/ObjectsList.h       |  3 +-
 alib2common/src/container/ObjectsMap.h        |  3 +-
 alib2common/src/container/ObjectsPair.h       |  3 +-
 alib2common/src/container/ObjectsSet.h        |  3 +-
 alib2common/src/container/ObjectsTree.h       |  3 +-
 alib2common/src/container/ObjectsTrie.h       |  3 +-
 alib2common/src/container/ObjectsVector.h     |  3 +-
 alib2common/src/primitive/PrimitiveFeatures.h | 32 --------------
 alib2std/src/extensions/variant.hpp           | 23 ++++++++++
 alib2std/test-src/extensions/VariantTest.cpp  | 15 +++++++
 alib2std/test-src/extensions/VariantTest.h    |  2 +
 14 files changed, 49 insertions(+), 93 deletions(-)
 delete mode 100644 alib2common/src/container/ContainerFeatures.h
 delete mode 100644 alib2common/src/primitive/PrimitiveFeatures.h

diff --git a/alib2common/src/common/createUnique.hpp b/alib2common/src/common/createUnique.hpp
index fac85d8c7e..6c47cb0647 100644
--- a/alib2common/src/common/createUnique.hpp
+++ b/alib2common/src/common/createUnique.hpp
@@ -24,7 +24,7 @@ namespace common {
  * @return created symbol
  */
 template < class T, class ... Alphabets >
-typename std::enable_if < ext::all_same < ext::set < T >, Alphabets ... >::value, T >::type createUnique ( const T & base, const Alphabets & ... alphabets ) {
+T createUnique ( const T & base, const Alphabets & ... alphabets ) {
 	T attempt = base;
 	unsigned i = 0;
 
diff --git a/alib2common/src/container/ContainerFeatures.h b/alib2common/src/container/ContainerFeatures.h
deleted file mode 100644
index 1e6efaa9fd..0000000000
--- a/alib2common/src/container/ContainerFeatures.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * ContainerFeatures.h
- *
- *  Created on: Jun 19, 2014
- *      Author: Jan Travnicek
- */
-
-#ifndef CONTAINER_FEATURES_H_
-#define CONTAINER_FEATURES_H_
-
-#include <object/Object.h>
-
-namespace container {
-
-enum class FEATURES {
-	SET,
-	VECTOR,
-	PAIR,
-	MAP
-};
-
-class Container;
-class ContainerBase;
-
-template < class ElementType = object::Object >
-class ObjectsDeque;
-template < class ElementType = object::Object >
-class ObjectsList;
-template < class KeyType = object::Object, class ValueType = object::Object >
-class ObjectsMap;
-template < class FirstType = object::Object, class SecondType = object::Object >
-class ObjectsPair;
-template < class ElementType = object::Object >
-class ObjectsSet;
-template < class ElementType = object::Object >
-class ObjectsTree;
-template < class KeyType = object::Object, class ValueType = object::Object >
-class ObjectsTrie;
-template < class ElementType = object::Object >
-class ObjectsVector;
-
-} /* namespace container */
-
-#endif /* CONTAINER_FEATURES_H_ */
diff --git a/alib2common/src/container/ObjectsDeque.h b/alib2common/src/container/ObjectsDeque.h
index 4d87b8e0a7..3abc1439f4 100644
--- a/alib2common/src/container/ObjectsDeque.h
+++ b/alib2common/src/container/ObjectsDeque.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -26,7 +25,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occurred.
  */
-template < class ElementType >
+template < class ElementType = object::Object >
 class ObjectsDeque final : public ext::deque < ElementType >, public ContainerBase {
 public:
 	explicit ObjectsDeque ( ext::deque < ElementType > );
diff --git a/alib2common/src/container/ObjectsList.h b/alib2common/src/container/ObjectsList.h
index 9d86a22aa9..8911a56de3 100644
--- a/alib2common/src/container/ObjectsList.h
+++ b/alib2common/src/container/ObjectsList.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -26,7 +25,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occured.
  */
-template < class ElementType >
+template < class ElementType = object::Object >
 class ObjectsList final : public ext::list < ElementType >, public ContainerBase {
 public:
 	explicit ObjectsList ( ext::list < ElementType > );
diff --git a/alib2common/src/container/ObjectsMap.h b/alib2common/src/container/ObjectsMap.h
index 5be8ce6930..f1e1b14e3c 100644
--- a/alib2common/src/container/ObjectsMap.h
+++ b/alib2common/src/container/ObjectsMap.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -27,7 +26,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occured.
  */
-template < class KeyType, class ValueType >
+template < class KeyType = object::Object, class ValueType = object::Object >
 class ObjectsMap final : public ext::map < KeyType, ValueType >, public ContainerBase {
 public:
 	explicit ObjectsMap ( ext::map < KeyType, ValueType > );
diff --git a/alib2common/src/container/ObjectsPair.h b/alib2common/src/container/ObjectsPair.h
index 21223d4fd6..e08ed37d0d 100644
--- a/alib2common/src/container/ObjectsPair.h
+++ b/alib2common/src/container/ObjectsPair.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -26,7 +25,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occured.
  */
-template < class FirstType, class SecondType >
+template < class FirstType = object::Object, class SecondType = object::Object >
 class ObjectsPair final : public ext::pair < FirstType, SecondType >, public ContainerBase {
 public:
 	explicit ObjectsPair ( FirstType firstObject, SecondType secondObject );
diff --git a/alib2common/src/container/ObjectsSet.h b/alib2common/src/container/ObjectsSet.h
index 631249cc81..0485d5d8da 100644
--- a/alib2common/src/container/ObjectsSet.h
+++ b/alib2common/src/container/ObjectsSet.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -26,7 +25,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occured.
  */
-template < class ElementType >
+template < class ElementType = object::Object >
 class ObjectsSet final : public ext::set < ElementType >, public ContainerBase {
 public:
 	explicit ObjectsSet ( ext::set < ElementType > );
diff --git a/alib2common/src/container/ObjectsTree.h b/alib2common/src/container/ObjectsTree.h
index 4a4cd3448e..b18c952abf 100644
--- a/alib2common/src/container/ObjectsTree.h
+++ b/alib2common/src/container/ObjectsTree.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -26,7 +25,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occured.
  */
-template < class ElementType >
+template < class ElementType = object::Object >
 class ObjectsTree final : public ext::tree < ElementType >, public ContainerBase {
 public:
 	explicit ObjectsTree ( ext::tree < ElementType > );
diff --git a/alib2common/src/container/ObjectsTrie.h b/alib2common/src/container/ObjectsTrie.h
index 65e49a2085..4634f28ac5 100644
--- a/alib2common/src/container/ObjectsTrie.h
+++ b/alib2common/src/container/ObjectsTrie.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -26,7 +25,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occured.
  */
-template < class KeyType, class ValueType >
+template < class KeyType = object::Object, class ValueType = object::Object >
 class ObjectsTrie final : public ext::trie < KeyType, ValueType >, public ContainerBase {
 public:
 	explicit ObjectsTrie ( ext::trie < KeyType, ValueType > );
diff --git a/alib2common/src/container/ObjectsVector.h b/alib2common/src/container/ObjectsVector.h
index c9fefc9dcc..bdf41b9db1 100644
--- a/alib2common/src/container/ObjectsVector.h
+++ b/alib2common/src/container/ObjectsVector.h
@@ -13,7 +13,6 @@
 #include <sstream>
 
 #include "ContainerBase.h"
-#include "ContainerFeatures.h"
 
 #include <object/UniqueObject.h>
 #include <object/ObjectFactory.h>
@@ -26,7 +25,7 @@ namespace container {
  * Basic container from which are derived all other containers.
  * Contains reason why the container occured.
  */
-template < class ElementType >
+template < class ElementType = object::Object >
 class ObjectsVector final : public ext::vector < ElementType >, public ContainerBase {
 public:
 	explicit ObjectsVector ( ext::vector < ElementType > );
diff --git a/alib2common/src/primitive/PrimitiveFeatures.h b/alib2common/src/primitive/PrimitiveFeatures.h
deleted file mode 100644
index e66479e7a7..0000000000
--- a/alib2common/src/primitive/PrimitiveFeatures.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * PrimitiveFeatures.h
- *
- *  Created on: Jun 19, 2014
- *      Author: Jan Travnicek
- */
-
-#ifndef PRIMITIVE_FEATURES_H_
-#define PRIMITIVE_FEATURES_H_
-
-namespace primitive {
-
-enum class FEATURES {
-	STRING,
-	CHAR,
-	INTEGER,
-	UNSIGNED,
-	BOOL
-};
-
-class Primitive;
-class PrimitiveBase;
-
-class String;
-class Integer;
-class Character;
-class Unsigned;
-class Bool;
-
-} /* namespace primitive */
-
-#endif /* PRIMITIVE_FEATURES_H_ */
diff --git a/alib2std/src/extensions/variant.hpp b/alib2std/src/extensions/variant.hpp
index 3b6b5255d8..9bf2bc7863 100644
--- a/alib2std/src/extensions/variant.hpp
+++ b/alib2std/src/extensions/variant.hpp
@@ -357,6 +357,29 @@ std::string to_string ( const ext::variant < Ts ... > & value ) {
 	return ( std::string ) value;
 }
 
+template < class Res, class T, class ... Ts >
+struct variant_builder_int {
+};
+
+template < class T >
+struct variant_builder_int < ext::variant < >, T > {
+	typedef T type;
+};
+
+template < class ... ResTs, class T >
+struct variant_builder_int < ext::variant < ResTs ... >, T > {
+	typedef ext::variant < ResTs ..., T > type;
+};
+
+template < class ... ResTs, class T, class ... Ts >
+struct variant_builder_int < ext::variant < ResTs ... >, T, Ts ... > {
+	typedef typename variant_builder_int < typename std::conditional < is_in < T, Ts ... >::value, ext::variant < ResTs ... >, ext::variant < ResTs ..., T > >::type, Ts ... >::type type;
+};
+
+template < class ... Ts >
+struct variant_builder : public variant_builder_int < ext::variant < >, Ts ... > {
+};
+
 } /* namespace ext */
 
 #endif /* __VARIANT_HPP_ */
diff --git a/alib2std/test-src/extensions/VariantTest.cpp b/alib2std/test-src/extensions/VariantTest.cpp
index 7cd176aa0a..079ad78fc1 100644
--- a/alib2std/test-src/extensions/VariantTest.cpp
+++ b/alib2std/test-src/extensions/VariantTest.cpp
@@ -192,3 +192,18 @@ void VariantTest::testSetVariant ( ) {
 	v = std::move ( v2 );
 	v.get < std::set < int > > ( ).insert ( 1 );
 }
+
+void VariantTest::testVariantBuilder ( ) {
+	bool same;
+	same = std::is_same < ext::variant_builder < int >::type, int >::value;
+	CPPUNIT_ASSERT ( same );
+
+	same = std::is_same < ext::variant_builder < int, int, int >::type, int >::value;
+	CPPUNIT_ASSERT ( same );
+
+	same = std::is_same < ext::variant_builder < double, int, char >::type, ext::variant < double, int, char > >::value;
+	CPPUNIT_ASSERT ( same );
+
+	same = std::is_same < ext::variant_builder < double, int, char, char, int, double >::type, ext::variant < char, int, double > >::value;
+	CPPUNIT_ASSERT ( same );
+}
diff --git a/alib2std/test-src/extensions/VariantTest.h b/alib2std/test-src/extensions/VariantTest.h
index 9fc101e2bb..da2eb7ea55 100644
--- a/alib2std/test-src/extensions/VariantTest.h
+++ b/alib2std/test-src/extensions/VariantTest.h
@@ -16,6 +16,7 @@ class VariantTest : public CppUnit::TestFixture
   CPPUNIT_TEST( testSizeT );
   CPPUNIT_TEST( testMoveSemantics );
   CPPUNIT_TEST( testSetVariant );
+  CPPUNIT_TEST( testVariantBuilder );
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -80,6 +81,7 @@ public:
   void testSizeT();
   void testMoveSemantics();
   void testSetVariant ( );
+  void testVariantBuilder ( );
 };
 
 namespace ext {
-- 
GitLab