From 51d8b21dde57b502b2c96b4272e21031d464f108 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com>
Date: Tue, 25 Jun 2019 22:56:38 +0200
Subject: [PATCH] Added type traits ViewTypeGetter and IsStatic.

---
 src/TNL/Containers/Array.h        | 14 ++++++++++++++
 src/TNL/Containers/ArrayView.h    |  8 ++++++++
 src/TNL/Containers/StaticArray.h  |  8 ++++++++
 src/TNL/Containers/StaticVector.h |  7 +++++++
 src/TNL/Containers/Vector.h       | 15 +++++++++++++++
 src/TNL/Containers/VectorView.h   |  7 +++++++
 src/TNL/TypeTraits.h              | 13 +++++++++++--
 7 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/src/TNL/Containers/Array.h b/src/TNL/Containers/Array.h
index 697f5de8fb..90eb61a56c 100644
--- a/src/TNL/Containers/Array.h
+++ b/src/TNL/Containers/Array.h
@@ -14,6 +14,7 @@
 #include <vector>
 
 #include <TNL/File.h>
+#include <TNL/TypeTraits.h>
 #include <TNL/Containers/ArrayView.h>
 
 namespace TNL {
@@ -619,6 +620,19 @@ template< typename Value, typename Device, typename Index >
 File& operator>>( File&& file, Array< Value, Device, Index >& array );
 
 } // namespace Containers
+
+template< typename Value, typename Device, typename Index >
+struct ViewTypeGetter< Containers::Array< Value, Device, Index > >
+{
+   using Type = Containers::ArrayView< Value, Device, Index >;
+};
+
+template< typename Value_, typename Device, typename Index >
+struct IsStatic< Containers::Array< Value_, Device, Index > >
+{
+   static constexpr bool Value = false;
+};
+
 } // namespace TNL
 
 #include <TNL/Containers/Array.hpp>
diff --git a/src/TNL/Containers/ArrayView.h b/src/TNL/Containers/ArrayView.h
index 356795194a..be67ed9e86 100644
--- a/src/TNL/Containers/ArrayView.h
+++ b/src/TNL/Containers/ArrayView.h
@@ -473,6 +473,14 @@ template< typename Value, typename Device, typename Index >
 File& operator>>( File&& file, ArrayView< Value, Device, Index > view );
 
 } // namespace Containers
+
+template< typename Value_, typename Device, typename Index >
+struct IsStatic< Containers::ArrayView< Value_, Device, Index > >
+{
+   static constexpr bool Value = false;
+};
+
+
 } // namespace TNL
 
 #include <TNL/Containers/ArrayView.hpp>
diff --git a/src/TNL/Containers/StaticArray.h b/src/TNL/Containers/StaticArray.h
index 4bc1a5066a..dea551a12c 100644
--- a/src/TNL/Containers/StaticArray.h
+++ b/src/TNL/Containers/StaticArray.h
@@ -12,6 +12,7 @@
 
 #include <TNL/String.h>
 #include <TNL/File.h>
+#include <TNL/TypeTraits.h>
 
 namespace TNL {
 namespace Containers {
@@ -556,6 +557,13 @@ template< int Size, typename Value >
 std::ostream& operator << ( std::ostream& str, const StaticArray< Size, Value >& a );
 
 } // namespace Containers
+
+template< int Size, typename Value_ >
+struct IsStatic< Containers::StaticArray< Size, Value_ > >
+{
+   static constexpr bool Value = true;
+};
+
 } // namespace TNL
 
 #include <TNL/Containers/StaticArray_impl.h>
diff --git a/src/TNL/Containers/StaticVector.h b/src/TNL/Containers/StaticVector.h
index 83b2883d94..2869eb51b5 100644
--- a/src/TNL/Containers/StaticVector.h
+++ b/src/TNL/Containers/StaticVector.h
@@ -742,4 +742,11 @@ Real TriangleArea( const StaticVector< 3, Real >& a,
 }
 
 } // namespace Containers
+
+template< int Size, typename Real >
+struct IsStatic< Containers::StaticVector< Size, Real > >
+{
+   static constexpr bool Value = true;
+};
+
 } // namespace TNL
diff --git a/src/TNL/Containers/Vector.h b/src/TNL/Containers/Vector.h
index 1d59face2f..0c074b7e56 100644
--- a/src/TNL/Containers/Vector.h
+++ b/src/TNL/Containers/Vector.h
@@ -10,6 +10,7 @@
 
 #pragma once
 
+#include <TNL/TypeTraits.h>
 #include <TNL/Containers/Array.h>
 #include <TNL/Containers/VectorView.h>
 
@@ -327,6 +328,20 @@ public:
 };
 
 } // namespace Containers
+
+template< typename Real, typename Device, typename Index >
+struct ViewTypeGetter< Containers::Vector< Real, Device, Index > >
+{
+   using Type = Containers::VectorView< Real, Device, Index >;
+};
+
+template< typename Real, typename Device, typename Index >
+struct IsStatic< Containers::Vector< Real, Device, Index > >
+{
+   static constexpr bool Value = false;
+};
+
+
 } // namespace TNL
 
 #include <TNL/Containers/Vector.hpp>
diff --git a/src/TNL/Containers/VectorView.h b/src/TNL/Containers/VectorView.h
index 85fdf4dae5..0d6483ac5e 100644
--- a/src/TNL/Containers/VectorView.h
+++ b/src/TNL/Containers/VectorView.h
@@ -214,6 +214,13 @@ public:
 };
 
 } // namespace Containers
+
+template< typename Real, typename Device, typename Index >
+struct IsStatic< Containers::VectorView< Real, Device, Index > >
+{
+   static constexpr bool Value = false;
+};
+
 } // namespace TNL
 
 #include <TNL/Containers/VectorView.hpp>
diff --git a/src/TNL/TypeTraits.h b/src/TNL/TypeTraits.h
index bb7e4a4d1e..d7a1a4f127 100644
--- a/src/TNL/TypeTraits.h
+++ b/src/TNL/TypeTraits.h
@@ -8,12 +8,21 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
+#pragma once
+#include <type_traits>
+
 namespace TNL {
 
 template< typename T >
-struct ViewType
+struct ViewTypeGetter
 {
    using Type = T;
 };
 
-} //namespace TNL
\ No newline at end of file
+template< typename T >
+struct IsStatic
+{
+   static constexpr bool Value = std::is_arithmetic< T >::value;
+};
+
+} //namespace TNL
-- 
GitLab