Loading src/TNL/Containers/Algorithms/ArrayAssignment.h +3 −3 Original line number Diff line number Diff line /*************************************************************************** ArrayOperations.h - description ArrayAssignment.h - description ------------------- begin : Jul 15, 2013 copyright : (C) 2013 by Tomas Oberhuber begin : Apr 4, 2019 copyright : (C) 2019 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ Loading src/TNL/Containers/Algorithms/VectorAssignment.h 0 → 100644 +87 −0 Original line number Diff line number Diff line /*************************************************************************** VectorAssignment.h - description ------------------- begin : Apr 4, 2019 copyright : (C) 2019 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include<type_traits> #include<utility> #include <TNL/Containers/Algorithms/VectorOperations.h> namespace TNL { namespace Containers { namespace Algorithms { namespace Details { /** * SFINAE for checking if T has getSize method */ template< typename T > class HasSubscriptOperator { private: typedef char YesType[1]; typedef char NoType[2]; template< typename C > static YesType& test( decltype(std::declval< C >()[0]) ); template< typename C > static NoType& test(...); public: static constexpr bool value = ( sizeof( test< T >(0) ) == sizeof( YesType ) ); }; } // namespace Details template< typename Vector, typename T, bool hasSubscriptOperator = Details::HasSubscriptOperator< T >::value > struct VectorAssignment{}; /** * \brief Specialization for assignment with subscript operator */ template< typename Vector, typename T > struct VectorAssignment< Vector, T, true > { static void resize( Vector& v, const T& t ) { v.setSize( t.getSize() ); } static void assign( Vector& v, const T& t ) { TNL_ASSERT_EQ( v.getSize(), t.getSize(), "The sizes of the vectors must be equal." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] = t[ i ]; }; }; /** * \brief Specialization for array-value assignment for other types. We assume * that T is convertible to Vector::ValueType. */ template< typename Vector, typename T > struct VectorAssignment< Vector, T, false > { static void resize( Vector& v, const T& t ) { }; static void assign( Vector& v, const T& t ) { TNL_ASSERT_GT( v.getSize(), 0, "Cannot assign value to empty vector." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] = t; }; }; } // namespace Algorithms } // namespace Containers } // namespace TNL src/TNL/Containers/StaticArray.h +33 −26 Original line number Diff line number Diff line Loading @@ -30,6 +30,12 @@ class StaticArray typedef int IndexType; enum { size = Size }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** * \brief Basic constructor. * Loading Loading @@ -72,11 +78,6 @@ class StaticArray */ static String getType(); /** * \brief Gets size of this array. */ __cuda_callable__ inline int getSize() const; /** * \brief Gets all data of this static array. Loading Loading @@ -188,6 +189,12 @@ class StaticArray< 1, Value > typedef int IndexType; enum { size = 1 }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** \brief See StaticArray::StaticArray().*/ __cuda_callable__ inline StaticArray(); Loading @@ -210,10 +217,6 @@ class StaticArray< 1, Value > /** \brief See StaticArray::getType().*/ static String getType(); /** \brief See StaticArray::getSize().*/ __cuda_callable__ inline int getSize() const; /** \brief See StaticArray::getData().*/ __cuda_callable__ inline Value* getData(); Loading Loading @@ -293,6 +296,12 @@ class StaticArray< 2, Value > typedef int IndexType; enum { size = 2 }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** \brief See StaticArray::StaticArray().*/ __cuda_callable__ inline StaticArray(); Loading Loading @@ -324,10 +333,6 @@ class StaticArray< 2, Value > /** \brief See StaticArray::getType().*/ static String getType(); /** \brief See StaticArray::getSize().*/ __cuda_callable__ inline int getSize() const; /** \brief See StaticArray::getData().*/ __cuda_callable__ inline Value* getData(); Loading Loading @@ -414,6 +419,12 @@ class StaticArray< 3, Value > typedef int IndexType; enum { size = 3 }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** \brief See StaticArray::StaticArray().*/ __cuda_callable__ inline StaticArray(); Loading Loading @@ -446,10 +457,6 @@ class StaticArray< 3, Value > /** \brief See StaticArray::getType().*/ static String getType(); /** \brief See StaticArray::getSize().*/ __cuda_callable__ inline int getSize() const; /** \brief See StaticArray::getData().*/ __cuda_callable__ inline Value* getData(); Loading src/TNL/Containers/StaticArray1D_impl.h +8 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,13 @@ namespace TNL { namespace Containers { template< typename Value > __cuda_callable__ constexpr int StaticArray< 1, Value >::getSize() { return size; } template< typename Value > __cuda_callable__ inline StaticArray< 1, Value >::StaticArray() Loading Loading @@ -54,13 +61,6 @@ String StaticArray< 1, Value >::getType() String( " >" ); } template< typename Value > __cuda_callable__ inline int StaticArray< 1, Value >::getSize() const { return size; } template< typename Value > __cuda_callable__ inline Value* StaticArray< 1, Value >::getData() Loading src/TNL/Containers/StaticArray2D_impl.h +8 −8 Original line number Diff line number Diff line Loading @@ -17,6 +17,13 @@ namespace TNL { namespace Containers { template< typename Value > __cuda_callable__ constexpr int StaticArray< 2, Value >::getSize() { return size; } template< typename Value > __cuda_callable__ inline StaticArray< 2, Value >::StaticArray() Loading Loading @@ -66,13 +73,6 @@ String StaticArray< 2, Value >::getType() String( " >" ); } template< typename Value > __cuda_callable__ inline int StaticArray< 2, Value >::getSize() const { return size; } template< typename Value > __cuda_callable__ inline Value* StaticArray< 2, Value >::getData() Loading Loading
src/TNL/Containers/Algorithms/ArrayAssignment.h +3 −3 Original line number Diff line number Diff line /*************************************************************************** ArrayOperations.h - description ArrayAssignment.h - description ------------------- begin : Jul 15, 2013 copyright : (C) 2013 by Tomas Oberhuber begin : Apr 4, 2019 copyright : (C) 2019 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ Loading
src/TNL/Containers/Algorithms/VectorAssignment.h 0 → 100644 +87 −0 Original line number Diff line number Diff line /*************************************************************************** VectorAssignment.h - description ------------------- begin : Apr 4, 2019 copyright : (C) 2019 by Tomas Oberhuber email : tomas.oberhuber@fjfi.cvut.cz ***************************************************************************/ /* See Copyright Notice in tnl/Copyright */ #pragma once #include<type_traits> #include<utility> #include <TNL/Containers/Algorithms/VectorOperations.h> namespace TNL { namespace Containers { namespace Algorithms { namespace Details { /** * SFINAE for checking if T has getSize method */ template< typename T > class HasSubscriptOperator { private: typedef char YesType[1]; typedef char NoType[2]; template< typename C > static YesType& test( decltype(std::declval< C >()[0]) ); template< typename C > static NoType& test(...); public: static constexpr bool value = ( sizeof( test< T >(0) ) == sizeof( YesType ) ); }; } // namespace Details template< typename Vector, typename T, bool hasSubscriptOperator = Details::HasSubscriptOperator< T >::value > struct VectorAssignment{}; /** * \brief Specialization for assignment with subscript operator */ template< typename Vector, typename T > struct VectorAssignment< Vector, T, true > { static void resize( Vector& v, const T& t ) { v.setSize( t.getSize() ); } static void assign( Vector& v, const T& t ) { TNL_ASSERT_EQ( v.getSize(), t.getSize(), "The sizes of the vectors must be equal." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] = t[ i ]; }; }; /** * \brief Specialization for array-value assignment for other types. We assume * that T is convertible to Vector::ValueType. */ template< typename Vector, typename T > struct VectorAssignment< Vector, T, false > { static void resize( Vector& v, const T& t ) { }; static void assign( Vector& v, const T& t ) { TNL_ASSERT_GT( v.getSize(), 0, "Cannot assign value to empty vector." ); for( decltype( v.getSize() ) i = 0; i < v.getSize(); i ++ ) v[ i ] = t; }; }; } // namespace Algorithms } // namespace Containers } // namespace TNL
src/TNL/Containers/StaticArray.h +33 −26 Original line number Diff line number Diff line Loading @@ -30,6 +30,12 @@ class StaticArray typedef int IndexType; enum { size = Size }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** * \brief Basic constructor. * Loading Loading @@ -72,11 +78,6 @@ class StaticArray */ static String getType(); /** * \brief Gets size of this array. */ __cuda_callable__ inline int getSize() const; /** * \brief Gets all data of this static array. Loading Loading @@ -188,6 +189,12 @@ class StaticArray< 1, Value > typedef int IndexType; enum { size = 1 }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** \brief See StaticArray::StaticArray().*/ __cuda_callable__ inline StaticArray(); Loading @@ -210,10 +217,6 @@ class StaticArray< 1, Value > /** \brief See StaticArray::getType().*/ static String getType(); /** \brief See StaticArray::getSize().*/ __cuda_callable__ inline int getSize() const; /** \brief See StaticArray::getData().*/ __cuda_callable__ inline Value* getData(); Loading Loading @@ -293,6 +296,12 @@ class StaticArray< 2, Value > typedef int IndexType; enum { size = 2 }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** \brief See StaticArray::StaticArray().*/ __cuda_callable__ inline StaticArray(); Loading Loading @@ -324,10 +333,6 @@ class StaticArray< 2, Value > /** \brief See StaticArray::getType().*/ static String getType(); /** \brief See StaticArray::getSize().*/ __cuda_callable__ inline int getSize() const; /** \brief See StaticArray::getData().*/ __cuda_callable__ inline Value* getData(); Loading Loading @@ -414,6 +419,12 @@ class StaticArray< 3, Value > typedef int IndexType; enum { size = 3 }; /** * \brief Gets size of this array. */ __cuda_callable__ static constexpr int getSize(); /** \brief See StaticArray::StaticArray().*/ __cuda_callable__ inline StaticArray(); Loading Loading @@ -446,10 +457,6 @@ class StaticArray< 3, Value > /** \brief See StaticArray::getType().*/ static String getType(); /** \brief See StaticArray::getSize().*/ __cuda_callable__ inline int getSize() const; /** \brief See StaticArray::getData().*/ __cuda_callable__ inline Value* getData(); Loading
src/TNL/Containers/StaticArray1D_impl.h +8 −8 Original line number Diff line number Diff line Loading @@ -16,6 +16,13 @@ namespace TNL { namespace Containers { template< typename Value > __cuda_callable__ constexpr int StaticArray< 1, Value >::getSize() { return size; } template< typename Value > __cuda_callable__ inline StaticArray< 1, Value >::StaticArray() Loading Loading @@ -54,13 +61,6 @@ String StaticArray< 1, Value >::getType() String( " >" ); } template< typename Value > __cuda_callable__ inline int StaticArray< 1, Value >::getSize() const { return size; } template< typename Value > __cuda_callable__ inline Value* StaticArray< 1, Value >::getData() Loading
src/TNL/Containers/StaticArray2D_impl.h +8 −8 Original line number Diff line number Diff line Loading @@ -17,6 +17,13 @@ namespace TNL { namespace Containers { template< typename Value > __cuda_callable__ constexpr int StaticArray< 2, Value >::getSize() { return size; } template< typename Value > __cuda_callable__ inline StaticArray< 2, Value >::StaticArray() Loading Loading @@ -66,13 +73,6 @@ String StaticArray< 2, Value >::getType() String( " >" ); } template< typename Value > __cuda_callable__ inline int StaticArray< 2, Value >::getSize() const { return size; } template< typename Value > __cuda_callable__ inline Value* StaticArray< 2, Value >::getData() Loading