Commit a0e9a56d authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Cleaned up inheriting constructors and assignment operators in Vector and VectorView

parent 970dd8fa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ getView( IndexType begin, IndexType end )
{
   if( end == 0 )
      end = getSize();
   return ViewType( &getData()[ begin ], end - begin );
   return ViewType( getData() + begin, end - begin );
}

template< typename Value,
@@ -350,7 +350,7 @@ getConstView( IndexType begin, IndexType end ) const
{
   if( end == 0 )
      end = getSize();
   return ConstViewType( &getData()[ begin ], end - begin );
   return ConstViewType( getData() + begin, end - begin );
}

template< typename Value,
+2 −2
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ getView( const IndexType begin, IndexType end )
{
   if( end == 0 )
      end = this->getSize();
   return ViewType( &getData()[ begin ], end - begin );;
   return ViewType( getData() + begin, end - begin );;
}

template< typename Value,
@@ -109,7 +109,7 @@ getConstView( const IndexType begin, IndexType end ) const
{
   if( end == 0 )
      end = this->getSize();
   return ConstViewType( &getData()[ begin ], end - begin );
   return ConstViewType( getData() + begin, end - begin );
}

// Copy-assignment does deep copy, just like regular array, but the sizes
+14 −81
Original line number Diff line number Diff line
@@ -44,85 +44,20 @@ public:
   using ViewType = VectorView< Real, Device, Index >;
   using ConstViewType = VectorView< std::add_const_t< Real >, Device, Index >;

   /** Subscript operator is inherited from the class \ref Array. */
   using Array< Real, Device, Index >::operator[];

   /**
    * \brief Basic constructor.
    *
    * Constructs an empty vector with zero size.
    */
   Vector();

   /**
    * \brief Constructor with vector size.
    *
    * \param size is number of vector elements.
    */
   Vector( const IndexType& size );

   /**
    * \brief Deep copy constructor with data pointer and size.
    *
    * This behavior of the Vector is deprecated and \ref VectorView should be used
    * instead.
    *
    * \param data Pointer to data.
    * \param size Number of vector elements.
    */
   Vector( Real* data,
           const IndexType& size );

   /**
    * \brief Copy constructor.
    *
    * \param vector is an vector to be copied.
    */
   explicit Vector( const Vector& vector );

   template< typename Real_, typename Device_, typename Index_ >
   Vector( const Vector< Real_, Device_, Index_ >& vector );

   /**
    * \brief Deep copy constructor with other vector.
    *
    * \param vector is an vector that is to be bound.
    * \param begin is the first index which should be bound.
    * \param size is number of array elements that should be bound.
    */
   Vector( Vector& vector,
           const IndexType& begin = 0,
           const IndexType& size = 0 );

   /**
    * \brief Move constructor.
    *
    * @param vector is an vector to be moved
    */
   Vector( Vector&& vector );

   /**
    * \brief Initialize the vector from initializer list, i.e. { ... }
    *
    * @param list Initializer list.
    */
   Vector( const std::initializer_list< Real >& list );

   /**
    * \brief Initialize the vector from std::list.
    *
    * @param list Input STL list.
    */
   template< typename InReal >
   Vector( const std::list< InReal >& list );

   /**
    * \brief Initialize the vector from std::vector.
    *
    * @param vector Input STL vector.
    */
   template< typename InReal >
   Vector( const std::vector< InReal >& vector );
   //! \brief Default constructor.
   Vector() = default;
   //! \brief Default copy constructor.
   explicit Vector( const Vector& ) = default;
   //! \brief Default move constructor.
   Vector( Vector&& ) = default;
   //! \brief Default copy-assignment operator.
   Vector& operator=( const Vector& ) = default;
   //! \brief Default move-assignment operator.
   Vector& operator=( Vector&& ) = default;

   //! Constructors and assignment operators are inherited from the class \ref Array.
   using Array< Real, Device, Index >::Array;
   using Array< Real, Device, Index >::operator=;

   /** \brief Returns type of vector Real value, Device type and the type of Index. */
   static String getType();
@@ -183,8 +118,6 @@ public:
                    const RealType& value,
                    const Scalar thisElementMultiplicator );

   Vector& operator = ( const Vector& v );

   template< typename Real_, typename Device_, typename Index_ >
   Vector& operator = ( const Vector< Real_, Device_, Index_ >& v );

+2 −108
Original line number Diff line number Diff line
@@ -17,102 +17,6 @@
namespace TNL {
namespace Containers {

template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >::
Vector()
{
}

template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >::
Vector( const IndexType& size )
:  Array< Real, Device, Index >( size )
{
}

template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >::
Vector( Real* data,
       const IndexType& size )
:  Array< Real, Device, Index >( data, size )
{
}

template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >::
Vector( const Vector< Real, Device, Index >& vector )
:  Array< Real, Device, Index >( vector )
{
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename Real_, typename Device_, typename Index_ >
Vector< Real, Device, Index >::
Vector( const Vector< Real_, Device_, Index_ >& vector )
:  Array< Real, Device, Index >( vector )
{
}


template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >::
Vector( Vector< Real, Device, Index >& vector,
        const IndexType& begin,
        const IndexType& size )
: Array< Real, Device, Index >( vector, begin, size )
{
}

template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >::
Vector( Vector< Real, Device, Index >&& vector )
:  Array< Real, Device, Index >( std::move( vector ) )
{
}

template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >::
Vector( const std::initializer_list< Real >& list )
:  Array< Real, Device, Index >( list )
{
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename InReal >
Vector< Real, Device, Index >::
Vector( const std::list< InReal >& list )
:  Array< Real, Device, Index >( list )
{
}

template< typename Real,
          typename Device,
          typename Index >
   template< typename InReal >
Vector< Real, Device, Index >::
Vector( const std::vector< InReal >& vector )
:   Array< Real, Device, Index >( vector )
{
}

template< typename Real,
          typename Device,
          typename Index >
@@ -145,7 +49,7 @@ getView( IndexType begin, IndexType end )
{
   if( end == 0 )
      end = this->getSize();
   return ViewType( &this->getData()[ begin ], end - begin );
   return ViewType( this->getData() + begin, end - begin );
}

template< typename Real,
@@ -157,7 +61,7 @@ getConstView( IndexType begin, IndexType end ) const
{
   if( end == 0 )
      end = this->getSize();
   return ConstViewType( &this->getData()[ begin ], end - begin );
   return ConstViewType( this->getData() + begin, end - begin );
}

template< typename Real,
@@ -202,16 +106,6 @@ addElement( const IndexType i,
   Algorithms::VectorOperations< Device >::addElement( *this, i, value, thisElementMultiplicator );
}

template< typename Real,
          typename Device,
          typename Index >
Vector< Real, Device, Index >&
Vector< Real, Device, Index >::operator = ( const Vector& vector )
{
   Array< Real, Device, Index >::operator=( vector );
   return *this;
}

template< typename Real,
          typename Device,
          typename Index >
+2 −11
Original line number Diff line number Diff line
@@ -42,18 +42,9 @@ public:
   using ViewType = VectorView< Real, Device, Index >;
   using ConstViewType = VectorView< std::add_const_t< Real >, Device, Index >;

   // inherit all ArrayView's constructors
#ifndef __NVCC__
   using BaseType::ArrayView;
#else
   // workaround for nvcc 8.0, otherwise the templated constructor below fails
   // (works fine in nvcc 9.0)
   //! Constructors and assignment operators are inherited from the class \ref Array.
   using ArrayView< Real, Device, Index >::ArrayView;
#endif
   using ArrayView< Real, Device, Index >::getData;

   /** Subscript operator is inherited from the class \ref Array. */
   using ArrayView< Real, Device, Index >::operator[];
   using ArrayView< Real, Device, Index >::operator=;

   // In C++14, default constructors cannot be inherited, although Clang
   // and GCC since version 7.0 inherit them.
Loading