Skip to content
Snippets Groups Projects
Commit 9207dcb1 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

ArrayView: added constructors to initialize const views by const references

parent 3105fb43
No related branches found
No related tags found
1 merge request!5Decoupling linear solvers from PDE solvers
......@@ -62,6 +62,16 @@ public:
__cuda_callable__
ArrayView( StaticArray< Size, Element_ >& array );
// these constructors will be used only when Element is const-qualified
// (const views are initializable by const references)
template< typename Element_ > // template catches both const and non-const qualified Element
__cuda_callable__
ArrayView( const Array< Element_, Device, Index >& array );
template< int Size, typename Element_ > // template catches both const and non-const qualified Element
__cuda_callable__
ArrayView( const StaticArray< Size, Element_ >& array );
// methods for rebinding (reinitialization)
__cuda_callable__
......
......@@ -56,6 +56,28 @@ ArrayView( StaticArray< Size, Element_ >& array )
this->bind( array.getData(), Size );
}
template< typename Element,
typename Device,
typename Index >
template< typename Element_ >
__cuda_callable__
ArrayView< Element, Device, Index >::
ArrayView( const Array< Element_, Device, Index >& array )
{
this->bind( array.getData(), array.getSize() );
}
template< typename Element,
typename Device,
typename Index >
template< int Size, typename Element_ >
__cuda_callable__
ArrayView< Element, Device, Index >::
ArrayView( const StaticArray< Size, Element_ >& array )
{
this->bind( array.getData(), Size );
}
// methods for rebinding (reinitialization)
template< typename Element,
typename Device,
......
......@@ -137,6 +137,7 @@ TYPED_TEST( ArrayViewTest, constructors )
{
using ArrayType = typename TestFixture::ArrayType;
using ViewType = typename TestFixture::ViewType;
using ConstViewType = ArrayView< const typename ArrayType::ElementType, typename ArrayType::DeviceType, typename ArrayType::IndexType >;
ArrayType a( 10 );
EXPECT_EQ( a.getSize(), 10 );
......@@ -154,6 +155,11 @@ TYPED_TEST( ArrayViewTest, constructors )
EXPECT_EQ( z.getData(), data );
EXPECT_EQ( z.getSize(), 10 );
}
// test initialization by const reference
const ArrayType& b = a;
ConstViewType b_view( b );
ConstViewType const_a_view( a );
}
TYPED_TEST( ArrayViewTest, bind )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment