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

Fixed default constructor of VectorView

parent f6ee280c
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -42,14 +42,21 @@ public:
#ifndef __NVCC__
   using BaseType::ArrayView;
#else
   // workaround for a bug in nvcc 8.0 (seems to be fixed in 9.0)
   // workaround for nvcc 8.0, otherwise the templated constructor below fails
   // (works fine in nvcc 9.0)
   using ArrayView< Real, Device, Index >::ArrayView;
#endif

   // In C++14, default constructors cannot be inherited, although Clang
   // and GCC since version 7.0 inherit them.
   // https://stackoverflow.com/a/51854172
   __cuda_callable__
   VectorView() = default;

   // initialization by base class is not a copy constructor so it has to be explicit
   template< typename Element_ >  // template catches both const and non-const qualified Element
   template< typename Real_ >  // template catches both const and non-const qualified Element
   __cuda_callable__
   VectorView( const ArrayView< Element_, Device, Index >& view )
   VectorView( const ArrayView< Real_, Device, Index >& view )
   : BaseType::ArrayView( view ) {}


+17 −0
Original line number Diff line number Diff line
@@ -755,6 +755,23 @@ TEST( VectorSpecialCasesTest, initializationOfVectorViewByArrayView )
   EXPECT_EQ( v_view.sum(), 0 );
}

TEST( VectorSpecialCasesTest, defaultConstructors )
{
   using ArrayType = Containers::Array< int, Devices::Host >;
   using VectorViewType = VectorView< int, Devices::Host >;
   using ArrayViewType = ArrayView< int, Devices::Host >;

   ArrayType a( 100 );
   a.setValue( 0 );

   ArrayViewType a_view;
   a_view.bind( a );

   VectorViewType v_view;
   v_view.bind( a );
   EXPECT_EQ( v_view.getData(), a_view.getData() );
}

#endif // HAVE_GTEST