Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Change tuple_size/tuple_element pair specializations to use const.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhemstad committed Jun 8, 2021
1 parent 20f1c6a commit 54a3d15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions testing/pair.cu
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ void TestPairTupleSize(void)
{
int result = thrust::tuple_size< thrust::pair<int,int> >::value;
ASSERT_EQUAL(2, result);

// test const pair
int const_result = thrust::tuple_size< thrust::pair<int,int> const >::value;
ASSERT_EQUAL(2, const_result);
};
DECLARE_UNITTEST(TestPairTupleSize);

Expand All @@ -229,6 +233,13 @@ void TestPairTupleElement(void)

ASSERT_EQUAL_QUIET(typeid(int), typeid(type0));
ASSERT_EQUAL_QUIET(typeid(float), typeid(type1));

// test const pair
typedef thrust::tuple_element<0, thrust::pair<int, float> const>::type const_type0;
typedef thrust::tuple_element<1, thrust::pair<int, float> const>::type const_type1;

ASSERT_EQUAL_QUIET(typeid(int const), typeid(const_type0));
ASSERT_EQUAL_QUIET(typeid(float const), typeid(const_type1));
};
DECLARE_UNITTEST(TestPairTupleElement);

Expand Down
6 changes: 3 additions & 3 deletions thrust/detail/pair.inl
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ template <typename T1, typename T2>

// specializations of tuple_element for pair
template<typename T1, typename T2>
struct tuple_element<0, pair<T1,T2> >
struct tuple_element<0, const pair<T1,T2> >
{
typedef T1 type;
}; // end tuple_element

template<typename T1, typename T2>
struct tuple_element<1, pair<T1,T2> >
struct tuple_element<1, const pair<T1,T2> >
{
typedef T2 type;
}; // end tuple_element


// specialization of tuple_size for pair
template<typename T1, typename T2>
struct tuple_size< pair<T1,T2 > >
struct tuple_size< const pair<T1,T2 > >
{
static const unsigned int value = 2;
}; // end tuple_size
Expand Down

0 comments on commit 54a3d15

Please sign in to comment.