thrust
tuple.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2018 NVIDIA Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
22 /*
23  * Copyright (C) 1999, 2000 Jaakko J√§rvi (jaakko.jarvi@cs.utu.fi)
24  *
25  * Distributed under the Boost Software License, Version 1.0.
26  * (See accompanying NOTICE file for the complete license)
27  *
28  * For more information, see http://www.boost.org
29  */
30 
31 #pragma once
32 
33 #include <thrust/detail/config.h>
34 #include <thrust/detail/tuple.inl>
35 #include <thrust/pair.h>
36 
37 namespace thrust
38 {
39 
51 struct null_type;
52 
65 template<int N, class T>
66  struct tuple_element
67 {
68  private:
69  typedef typename T::tail_type Next;
70 
71  public:
74  typedef typename tuple_element<N-1, Next>::type type;
75 }; // end tuple_element
76 
85 template<class T>
86  struct tuple_size
87 {
90  static const int value = 1 + tuple_size<typename T::tail_type>::value;
91 }; // end tuple_size
92 
93 // get function for non-const cons-lists, returns a reference to the element
94 
118 template<int N, class HT, class TT>
119 __host__ __device__
120 inline typename access_traits<
122  >::non_const_type
123 get(detail::cons<HT, TT>& t);
124 
125 
149 template<int N, class HT, class TT>
150 __host__ __device__
151 inline typename access_traits<
153  >::const_type
154 get(const detail::cons<HT, TT>& t);
155 
156 
157 
195 template <class T0, class T1, class T2, class T3, class T4,
196  class T5, class T6, class T7, class T8, class T9>
197  class tuple :
198  public detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
199 {
203  private:
204  typedef typename detail::map_tuple_to_cons<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type inherited;
205 
209  public:
212  inline __host__ __device__
213  tuple(void) {}
214 
219  inline __host__ __device__
220  tuple(typename access_traits<T0>::parameter_type t0)
221  : inherited(t0,
222  static_cast<const null_type&>(null_type()),
223  static_cast<const null_type&>(null_type()),
224  static_cast<const null_type&>(null_type()),
225  static_cast<const null_type&>(null_type()),
226  static_cast<const null_type&>(null_type()),
227  static_cast<const null_type&>(null_type()),
228  static_cast<const null_type&>(null_type()),
229  static_cast<const null_type&>(null_type()),
230  static_cast<const null_type&>(null_type())) {}
231 
238  inline __host__ __device__
239  tuple(typename access_traits<T0>::parameter_type t0,
240  typename access_traits<T1>::parameter_type t1)
241  : inherited(t0, t1,
242  static_cast<const null_type&>(null_type()),
243  static_cast<const null_type&>(null_type()),
244  static_cast<const null_type&>(null_type()),
245  static_cast<const null_type&>(null_type()),
246  static_cast<const null_type&>(null_type()),
247  static_cast<const null_type&>(null_type()),
248  static_cast<const null_type&>(null_type()),
249  static_cast<const null_type&>(null_type())) {}
250 
254  inline __host__ __device__
255  tuple(typename access_traits<T0>::parameter_type t0,
256  typename access_traits<T1>::parameter_type t1,
257  typename access_traits<T2>::parameter_type t2)
258  : inherited(t0, t1, t2,
259  static_cast<const null_type&>(null_type()),
260  static_cast<const null_type&>(null_type()),
261  static_cast<const null_type&>(null_type()),
262  static_cast<const null_type&>(null_type()),
263  static_cast<const null_type&>(null_type()),
264  static_cast<const null_type&>(null_type()),
265  static_cast<const null_type&>(null_type())) {}
266 
267  inline __host__ __device__
268  tuple(typename access_traits<T0>::parameter_type t0,
269  typename access_traits<T1>::parameter_type t1,
270  typename access_traits<T2>::parameter_type t2,
271  typename access_traits<T3>::parameter_type t3)
272  : inherited(t0, t1, t2, t3,
273  static_cast<const null_type&>(null_type()),
274  static_cast<const null_type&>(null_type()),
275  static_cast<const null_type&>(null_type()),
276  static_cast<const null_type&>(null_type()),
277  static_cast<const null_type&>(null_type()),
278  static_cast<const null_type&>(null_type())) {}
279 
280  inline __host__ __device__
281  tuple(typename access_traits<T0>::parameter_type t0,
282  typename access_traits<T1>::parameter_type t1,
283  typename access_traits<T2>::parameter_type t2,
284  typename access_traits<T3>::parameter_type t3,
285  typename access_traits<T4>::parameter_type t4)
286  : inherited(t0, t1, t2, t3, t4,
287  static_cast<const null_type&>(null_type()),
288  static_cast<const null_type&>(null_type()),
289  static_cast<const null_type&>(null_type()),
290  static_cast<const null_type&>(null_type()),
291  static_cast<const null_type&>(null_type())) {}
292 
293  inline __host__ __device__
294  tuple(typename access_traits<T0>::parameter_type t0,
295  typename access_traits<T1>::parameter_type t1,
296  typename access_traits<T2>::parameter_type t2,
297  typename access_traits<T3>::parameter_type t3,
298  typename access_traits<T4>::parameter_type t4,
299  typename access_traits<T5>::parameter_type t5)
300  : inherited(t0, t1, t2, t3, t4, t5,
301  static_cast<const null_type&>(null_type()),
302  static_cast<const null_type&>(null_type()),
303  static_cast<const null_type&>(null_type()),
304  static_cast<const null_type&>(null_type())) {}
305 
306  inline __host__ __device__
307  tuple(typename access_traits<T0>::parameter_type t0,
308  typename access_traits<T1>::parameter_type t1,
309  typename access_traits<T2>::parameter_type t2,
310  typename access_traits<T3>::parameter_type t3,
311  typename access_traits<T4>::parameter_type t4,
312  typename access_traits<T5>::parameter_type t5,
313  typename access_traits<T6>::parameter_type t6)
314  : inherited(t0, t1, t2, t3, t4, t5, t6,
315  static_cast<const null_type&>(null_type()),
316  static_cast<const null_type&>(null_type()),
317  static_cast<const null_type&>(null_type())) {}
318 
319  inline __host__ __device__
320  tuple(typename access_traits<T0>::parameter_type t0,
321  typename access_traits<T1>::parameter_type t1,
322  typename access_traits<T2>::parameter_type t2,
323  typename access_traits<T3>::parameter_type t3,
324  typename access_traits<T4>::parameter_type t4,
325  typename access_traits<T5>::parameter_type t5,
326  typename access_traits<T6>::parameter_type t6,
327  typename access_traits<T7>::parameter_type t7)
328  : inherited(t0, t1, t2, t3, t4, t5, t6, t7,
329  static_cast<const null_type&>(null_type()),
330  static_cast<const null_type&>(null_type())) {}
331 
332  inline __host__ __device__
333  tuple(typename access_traits<T0>::parameter_type t0,
334  typename access_traits<T1>::parameter_type t1,
335  typename access_traits<T2>::parameter_type t2,
336  typename access_traits<T3>::parameter_type t3,
337  typename access_traits<T4>::parameter_type t4,
338  typename access_traits<T5>::parameter_type t5,
339  typename access_traits<T6>::parameter_type t6,
340  typename access_traits<T7>::parameter_type t7,
341  typename access_traits<T8>::parameter_type t8)
342  : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8,
343  static_cast<const null_type&>(null_type())) {}
344 
345  inline __host__ __device__
346  tuple(typename access_traits<T0>::parameter_type t0,
347  typename access_traits<T1>::parameter_type t1,
348  typename access_traits<T2>::parameter_type t2,
349  typename access_traits<T3>::parameter_type t3,
350  typename access_traits<T4>::parameter_type t4,
351  typename access_traits<T5>::parameter_type t5,
352  typename access_traits<T6>::parameter_type t6,
353  typename access_traits<T7>::parameter_type t7,
354  typename access_traits<T8>::parameter_type t8,
355  typename access_traits<T9>::parameter_type t9)
356  : inherited(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) {}
357 
358 
359  template<class U1, class U2>
360  inline __host__ __device__
361  tuple(const detail::cons<U1, U2>& p) : inherited(p) {}
362 
363  __thrust_exec_check_disable__
364  template <class U1, class U2>
365  inline __host__ __device__
366  tuple& operator=(const detail::cons<U1, U2>& k)
367  {
368  inherited::operator=(k);
369  return *this;
370  }
371 
378  __thrust_exec_check_disable__
379  template <class U1, class U2>
380  __host__ __device__ inline
381  tuple& operator=(const thrust::pair<U1, U2>& k) {
382  //BOOST_STATIC_ASSERT(length<tuple>::value == 2);// check_length = 2
383  this->head = k.first;
384  this->tail.head = k.second;
385  return *this;
386  }
387 
392  inline __host__ __device__
393  void swap(tuple &t)
394  {
395  inherited::swap(t);
396  }
397 };
398 
402 template <>
403 class tuple<null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type, null_type> :
404  public null_type
405 {
406 public:
407  typedef null_type inherited;
408 };
409 
420 template<class T0>
421 __host__ __device__ inline
422  typename detail::make_tuple_mapper<T0>::type
423  make_tuple(const T0& t0);
424 
436 template<class T0, class T1>
437 __host__ __device__ inline
438  typename detail::make_tuple_mapper<T0, T1>::type
439  make_tuple(const T0& t0, const T1& t1);
440 
447 template<typename T0>
448 __host__ __device__ inline
449 tuple<T0&> tie(T0& t0);
450 
462 template<typename T0, typename T1>
463 __host__ __device__ inline
464 tuple<T0&,T1&> tie(T0& t0, T1& t1);
465 
471 template<
472  typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9,
473  typename U0, typename U1, typename U2, typename U3, typename U4, typename U5, typename U6, typename U7, typename U8, typename U9
474 >
475 inline __host__ __device__
478 
479 
480 
484 template<class T0, class T1, class T2>
485 __host__ __device__ inline
486  typename detail::make_tuple_mapper<T0, T1, T2>::type
487  make_tuple(const T0& t0, const T1& t1, const T2& t2);
488 
489 template<class T0, class T1, class T2, class T3>
490 __host__ __device__ inline
491  typename detail::make_tuple_mapper<T0, T1, T2, T3>::type
492  make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3);
493 
494 template<class T0, class T1, class T2, class T3, class T4>
495 __host__ __device__ inline
496  typename detail::make_tuple_mapper<T0, T1, T2, T3, T4>::type
497  make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4);
498 
499 template<class T0, class T1, class T2, class T3, class T4, class T5>
500 __host__ __device__ inline
501  typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5>::type
502  make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5);
503 
504 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6>
505 __host__ __device__ inline
506  typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6>::type
507  make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6);
508 
509 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
510 __host__ __device__ inline
511  typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7>::type
512  make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7);
513 
514 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
515 __host__ __device__ inline
516  typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7, T8>::type
517  make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8);
518 
519 template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9>
520 __host__ __device__ inline
521  typename detail::make_tuple_mapper<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::type
522  make_tuple(const T0& t0, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9);
523 
524 template<typename T0, typename T1, typename T2>
525 __host__ __device__ inline
526 tuple<T0&,T1&,T2&> tie(T0 &t0, T1 &t1, T2 &t2);
527 
528 template<typename T0, typename T1, typename T2, typename T3>
529 __host__ __device__ inline
530 tuple<T0&,T1&,T2&,T3&> tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3);
531 
532 template<typename T0, typename T1, typename T2, typename T3, typename T4>
533 __host__ __device__ inline
534 tuple<T0&,T1&,T2&,T3&,T4&> tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4);
535 
536 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
537 __host__ __device__ inline
538 tuple<T0&,T1&,T2&,T3&,T4&,T5&> tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5);
539 
540 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
541 __host__ __device__ inline
542 tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&> tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6);
543 
544 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
545 __host__ __device__ inline
546 tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&> tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7);
547 
548 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
549 __host__ __device__ inline
550 tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&,T8&> tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8);
551 
552 template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
553 __host__ __device__ inline
554 tuple<T0&,T1&,T2&,T3&,T4&,T5&,T6&,T7&,T8&,T9&> tie(T0 &t0, T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8, T9 &t9);
555 
556 
557 __host__ __device__ inline
558 bool operator==(const null_type&, const null_type&);
559 
560 __host__ __device__ inline
561 bool operator>=(const null_type&, const null_type&);
562 
563 __host__ __device__ inline
564 bool operator<=(const null_type&, const null_type&);
565 
566 __host__ __device__ inline
567 bool operator!=(const null_type&, const null_type&);
568 
569 __host__ __device__ inline
570 bool operator<(const null_type&, const null_type&);
571 
572 __host__ __device__ inline
573 bool operator>(const null_type&, const null_type&);
574 
584 } // end thrust
585 
__host__ __device__ void swap(tuple &t)
Definition: tuple.h:393
__host__ __device__ detail::make_tuple_mapper< T0 >::type make_tuple(const T0 &t0)
Definition: tuple.h:197
second_type second
Definition: pair.h:65
Definition: pair.h:49
Definition: pair.h:231
__host__ __device__ tuple(typename access_traits< T0 >::parameter_type t0)
Definition: tuple.h:220
__host__ __device__ bool operator>=(const pair< T1, T2 > &x, const pair< T1, T2 > &y)
__host__ __device__ bool operator<(const pair< T1, T2 > &x, const pair< T1, T2 > &y)
__host__ __device__ tuple(typename access_traits< T0 >::parameter_type t0, typename access_traits< T1 >::parameter_type t1)
Definition: tuple.h:239
thrust is the top-level namespace which contains all Thrust functions and types.
Definition: addressof.h:14
__thrust_exec_check_disable__ __host__ __device__ tuple & operator=(const thrust::pair< U1, U2 > &k)
Definition: tuple.h:381
__host__ __device__ tuple(void)
Definition: tuple.h:213
__host__ __device__ bool operator<=(const pair< T1, T2 > &x, const pair< T1, T2 > &y)
__host__ __device__ bool operator!=(const complex< T0 > &x, const complex< T1 > &y)
A type encapsulating a heterogeneous pair of elements.
__host__ __device__ bool operator==(const complex< T0 > &x, const complex< T1 > &y)
first_type first
Definition: pair.h:61
__host__ __device__ tuple< T0 & > tie(T0 &t0)
__host__ __device__ void swap(tuple< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9 > &x, tuple< U0, U1, U2, U3, U4, U5, U6, U7, U8, U9 > &y)
tuple_element< N-1, Next >::type type
Definition: tuple.h:74
Definition: pair.h:240
__host__ __device__ void swap(device_reference< T > x, device_reference< T > y)
__host__ __device__ bool operator>(const pair< T1, T2 > &x, const pair< T1, T2 > &y)