Commit 0da92ca5 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Fixed the method SharedPointer::swap.

parent 96901122
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <cstring>   // std::memcpy, std::memcmp
#include <cstddef>   // std::nullptr_t
#include <algorithm> // swap

//#define TNL_DEBUG_SHARED_POINTERS

@@ -67,7 +68,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer

      using ObjectType = Object;
      using DeviceType = Devices::Cuda; 
      using ThisType = SharedPointer<  Object, Devices::Host >;
      using ThisType = SharedPointer<  Object, Devices::Cuda >;

      SharedPointer( std::nullptr_t )
      : pd( nullptr )
@@ -321,7 +322,7 @@ class SharedPointer< Object, Devices::Cuda > : public SmartPointer

      using ObjectType = Object;
      using DeviceType = Devices::Cuda; 
      using ThisType = SharedPointer<  Object, Devices::Host >;
      using ThisType = SharedPointer<  Object, Devices::Cuda >;

      SharedPointer( std::nullptr_t )
      : pd( nullptr ),
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <TNL/Pointers/SmartPointer.h>

#include <cstddef>   // std::nullptr_t
#include <algorithm> // swap

namespace TNL {
namespace Pointers {
+4 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <cstring>   // std::memcpy, std::memcmp
#include <cstddef>   // std::nullptr_t
#include <algorithm> // swap

namespace TNL {
namespace Pointers {
@@ -44,7 +45,7 @@ class SharedPointer< Object, Devices::MIC > : public SmartPointer

      using ObjectType = Object;
      using DeviceType = Devices::MIC; 
      using ThisType = SharedPointer<  Object, Devices::Host >;
      using ThisType = SharedPointer<  Object, Devices::MIC >;

      SharedPointer( std::nullptr_t )
      : pd( nullptr ),
+13 −0
Original line number Diff line number Diff line
@@ -121,6 +121,19 @@ TEST( SharedPointerCudaTest, nullptrAssignement )
#endif
}

TEST( SharedPointerCudaTest, swap )
{
#ifdef HAVE_CUDA
   using TestType = Pointers::SharedPointer< double, Devices::Cuda >;
   TestType p1( 1 ), p2( 2 );
   
   p1.swap( p2 );
   
   ASSERT_EQ( *p1, 2 );
   ASSERT_EQ( *p2, 1 );
#endif
}


#endif

+11 −0
Original line number Diff line number Diff line
@@ -51,6 +51,17 @@ TEST( SharedPointerCudaTest, nullptrAssignement )
   ASSERT_FALSE( p2 );
}

TEST( SharedPointerCudaTest, swap )
{
   using TestType = Pointers::SharedPointer< double, Devices::Host >;
   TestType p1( 1 ), p2( 2 );
   
   p1.swap( p2 );
   
   ASSERT_EQ( *p1, 2 );
   ASSERT_EQ( *p2, 1 );
}

#endif

#include "../GtestMissingError.h"