Commit 52c9d170 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Added Array constructor with size and value.

parent 1ac668ec
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -137,6 +137,15 @@ class Array
       */
      explicit Array( const IndexType& size, const AllocatorType& allocator = AllocatorType() );

      /**
       * \brief Constructs an array with given size and value.
       *
       * \param size The number of array elements to be allocated.
       * \param value The value all elements will be set to.
       * \param allocator The allocator to be associated with this array.
       */
      explicit Array( const IndexType& size, const Value& value, const AllocatorType& allocator = AllocatorType() );

      /**
       * \brief Constructs an array with given size and copies data from given
       * pointer.
+12 −0
Original line number Diff line number Diff line
@@ -62,6 +62,18 @@ Array( const IndexType& size, const AllocatorType& allocator )
   this->setSize( size );
}

template< typename Value,
          typename Device,
          typename Index,
          typename Allocator >
Array< Value, Device, Index, Allocator >::
Array( const IndexType& size, const Value& value, const AllocatorType& allocator )
: allocator( allocator )
{
   this->setSize( size );
   ( *this ) = value;
}

template< typename Value,
          typename Device,
          typename Index,
+5 −0
Original line number Diff line number Diff line
@@ -135,6 +135,11 @@ TYPED_TEST( ArrayTest, constructors )
   v = 0;
   EXPECT_EQ( v.getSize(), 10 );

   ArrayType vv( 10, 4 );
   EXPECT_EQ( vv.getSize(), 10 );
   for( int i = 0; i < 10; i++ )
      EXPECT_EQ( vv.getElement( i ), 4 );

   // deep copy
   ArrayType w( v );
   EXPECT_NE( w.getData(), v.getData() );