+#include <iostream>
 #include <unittest/unittest.h>
 #include <thrust/sort.h>
 #include <thrust/memory.h>

DECLARE_UNITTEST(TestSelectSystemSameTypes);


template<typename T>
  thrust::pair<thrust::pointer<T,my_tag>, std::ptrdiff_t>
    get_temporary_buffer(my_tag, size_t n)
{
  // communicate that my version of get_temporary_buffer
  // was correctly dispatched
  throw my_tag();
}

void TestGetTemporaryBufferDispatchImplicit()
{
  bool correctly_dispatched = false;

  try
  {
    thrust::device_vector<int> vec(2);

    // call something we know will invoke get_temporary_buffer
    thrust::sort(thrust::retag<my_tag>(vec.begin()),
                 thrust::retag<my_tag>(vec.end()));
  }
  catch(my_tag)
  {
    correctly_dispatched = true;
  }

  ASSERT_EQUAL(true, correctly_dispatched);
}
DECLARE_UNITTEST(TestGetTemporaryBufferDispatchImplicit);


void TestSelectSystemSameTypes()
{
  using thrust::system::detail::generic::select_system;

  // select_system(host_system_tag, host_system_tag) should return host_system_tag
  bool is_host_system_tag = is_same(thrust::host_system_tag(), select_system(thrust::host_system_tag(), thrust::host_system_tag()));
  ASSERT_EQUAL(true, is_host_system_tag);

  // select_system(device_system_tag, device_system_tag) should return device_system_tag
  bool is_device_system_tag = is_same(thrust::device_system_tag(), select_system(thrust::device_system_tag(), thrust::device_system_tag()));
