Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/tbb/compat/tuple is written in an unsupported language. File is not indexed.

0001 /*
0002     Copyright (c) 2005-2020 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 #include "../internal/_deprecated_header_message_guard.h"
0018 
0019 #if !defined(__TBB_show_deprecation_message_tuple_H) && defined(__TBB_show_deprecated_header_message)
0020 #define  __TBB_show_deprecation_message_tuple_H
0021 #pragma message("TBB Warning: tbb/compat/tuple is deprecated. For details, please see Deprecated Features appendix in the TBB reference manual.")
0022 #endif
0023 
0024 #if defined(__TBB_show_deprecated_header_message)
0025 #undef __TBB_show_deprecated_header_message
0026 #endif
0027 
0028 #ifndef __TBB_tuple_H
0029 #define __TBB_tuple_H
0030 
0031 #define __TBB_tuple_H_include_area
0032 #include "../internal/_warning_suppress_enable_notice.h"
0033 
0034 #include <utility>
0035 #include "../tbb_stddef.h"
0036 
0037 // build preprocessor variables for varying number of arguments
0038 // Need the leading comma so the empty __TBB_T_PACK will not cause a syntax error.
0039 #if __TBB_VARIADIC_MAX <= 5
0040 #define __TBB_T_PACK
0041 #define __TBB_U_PACK
0042 #define __TBB_TYPENAME_T_PACK
0043 #define __TBB_TYPENAME_U_PACK
0044 #define __TBB_NULL_TYPE_PACK
0045 #define __TBB_REF_T_PARAM_PACK
0046 #define __TBB_CONST_REF_T_PARAM_PACK
0047 #define __TBB_T_PARAM_LIST_PACK
0048 #define __TBB_CONST_NULL_REF_PACK
0049 //
0050 #elif __TBB_VARIADIC_MAX == 6
0051 #define __TBB_T_PACK ,__T5
0052 #define __TBB_U_PACK ,__U5
0053 #define __TBB_TYPENAME_T_PACK , typename __T5
0054 #define __TBB_TYPENAME_U_PACK , typename __U5
0055 #define __TBB_NULL_TYPE_PACK , null_type
0056 #define __TBB_REF_T_PARAM_PACK ,__T5& t5
0057 #define __TBB_CONST_REF_T_PARAM_PACK ,const __T5& t5
0058 #define __TBB_T_PARAM_LIST_PACK ,t5
0059 #define __TBB_CONST_NULL_REF_PACK , const null_type&
0060 //
0061 #elif __TBB_VARIADIC_MAX == 7
0062 #define __TBB_T_PACK ,__T5, __T6
0063 #define __TBB_U_PACK ,__U5, __U6
0064 #define __TBB_TYPENAME_T_PACK , typename __T5 , typename __T6
0065 #define __TBB_TYPENAME_U_PACK , typename __U5 , typename __U6
0066 #define __TBB_NULL_TYPE_PACK , null_type, null_type
0067 #define __TBB_REF_T_PARAM_PACK ,__T5& t5, __T6& t6
0068 #define __TBB_CONST_REF_T_PARAM_PACK ,const __T5& t5, const __T6& t6
0069 #define __TBB_T_PARAM_LIST_PACK ,t5 ,t6
0070 #define __TBB_CONST_NULL_REF_PACK , const null_type&, const null_type&
0071 //
0072 #elif __TBB_VARIADIC_MAX == 8
0073 #define __TBB_T_PACK ,__T5, __T6, __T7
0074 #define __TBB_U_PACK ,__U5, __U6, __U7
0075 #define __TBB_TYPENAME_T_PACK , typename __T5 , typename __T6, typename __T7
0076 #define __TBB_TYPENAME_U_PACK , typename __U5 , typename __U6, typename __U7
0077 #define __TBB_NULL_TYPE_PACK , null_type, null_type, null_type
0078 #define __TBB_REF_T_PARAM_PACK ,__T5& t5, __T6& t6, __T7& t7
0079 #define __TBB_CONST_REF_T_PARAM_PACK , const __T5& t5, const __T6& t6, const __T7& t7
0080 #define __TBB_T_PARAM_LIST_PACK ,t5 ,t6 ,t7
0081 #define __TBB_CONST_NULL_REF_PACK , const null_type&, const null_type&, const null_type&
0082 //
0083 #elif __TBB_VARIADIC_MAX == 9
0084 #define __TBB_T_PACK ,__T5, __T6, __T7, __T8
0085 #define __TBB_U_PACK ,__U5, __U6, __U7, __U8
0086 #define __TBB_TYPENAME_T_PACK , typename __T5, typename __T6, typename __T7, typename __T8
0087 #define __TBB_TYPENAME_U_PACK , typename __U5, typename __U6, typename __U7, typename __U8
0088 #define __TBB_NULL_TYPE_PACK , null_type, null_type, null_type, null_type
0089 #define __TBB_REF_T_PARAM_PACK ,__T5& t5, __T6& t6, __T7& t7, __T8& t8
0090 #define __TBB_CONST_REF_T_PARAM_PACK , const __T5& t5, const __T6& t6, const __T7& t7, const __T8& t8
0091 #define __TBB_T_PARAM_LIST_PACK ,t5 ,t6 ,t7 ,t8
0092 #define __TBB_CONST_NULL_REF_PACK , const null_type&, const null_type&, const null_type&, const null_type&
0093 //
0094 #elif __TBB_VARIADIC_MAX >= 10
0095 #define __TBB_T_PACK ,__T5, __T6, __T7, __T8, __T9
0096 #define __TBB_U_PACK ,__U5, __U6, __U7, __U8, __U9
0097 #define __TBB_TYPENAME_T_PACK , typename __T5, typename __T6, typename __T7, typename __T8, typename __T9
0098 #define __TBB_TYPENAME_U_PACK , typename __U5, typename __U6, typename __U7, typename __U8, typename __U9
0099 #define __TBB_NULL_TYPE_PACK , null_type, null_type, null_type, null_type, null_type
0100 #define __TBB_REF_T_PARAM_PACK ,__T5& t5, __T6& t6, __T7& t7, __T8& t8, __T9& t9
0101 #define __TBB_CONST_REF_T_PARAM_PACK , const __T5& t5, const __T6& t6, const __T7& t7, const __T8& t8, const __T9& t9
0102 #define __TBB_T_PARAM_LIST_PACK ,t5 ,t6 ,t7 ,t8 ,t9
0103 #define __TBB_CONST_NULL_REF_PACK , const null_type&, const null_type&, const null_type&, const null_type&, const null_type&
0104 #endif
0105 
0106 
0107 
0108 namespace tbb {
0109 namespace interface5 {
0110 
0111 namespace internal {
0112 struct null_type { };
0113 }
0114 using internal::null_type;
0115 
0116 // tuple forward declaration
0117 template <typename __T0=null_type, typename __T1=null_type, typename __T2=null_type,
0118           typename __T3=null_type, typename __T4=null_type
0119 #if __TBB_VARIADIC_MAX >= 6
0120 , typename __T5=null_type
0121 #if __TBB_VARIADIC_MAX >= 7
0122 , typename __T6=null_type
0123 #if __TBB_VARIADIC_MAX >= 8
0124 , typename __T7=null_type
0125 #if __TBB_VARIADIC_MAX >= 9
0126 , typename __T8=null_type
0127 #if __TBB_VARIADIC_MAX >= 10
0128 , typename __T9=null_type
0129 #endif
0130 #endif
0131 #endif
0132 #endif
0133 #endif
0134 >
0135 class tuple;
0136 
0137 namespace internal {
0138 
0139 // const null_type temp
0140 inline const null_type cnull() { return null_type(); }
0141 
0142 // cons forward declaration
0143 template <typename __HT, typename __TT> struct cons;
0144 
0145 // type of a component of the cons
0146 template<int __N, typename __T>
0147 struct component {
0148     typedef typename __T::tail_type next;
0149     typedef typename component<__N-1,next>::type type;
0150 };
0151 
0152 template<typename __T>
0153 struct component<0,__T> {
0154     typedef typename __T::head_type type;
0155 };
0156 
0157 template<>
0158 struct component<0,null_type> {
0159     typedef null_type type;
0160 };
0161 
0162 // const version of component
0163 
0164 template<int __N, typename __T>
0165 struct component<__N, const __T>
0166 {
0167     typedef typename __T::tail_type next;
0168     typedef const typename component<__N-1,next>::type type;
0169 };
0170 
0171 template<typename __T>
0172 struct component<0, const __T>
0173 {
0174     typedef const typename __T::head_type type;
0175 };
0176 
0177 
0178 // helper class for getting components of cons
0179 template< int __N>
0180 struct get_helper {
0181 template<typename __HT, typename __TT>
0182 inline static typename component<__N, cons<__HT,__TT> >::type& get(cons<__HT,__TT>& ti) {
0183     return get_helper<__N-1>::get(ti.tail);
0184 }
0185 template<typename __HT, typename __TT>
0186 inline static typename component<__N, cons<__HT,__TT> >::type const& get(const cons<__HT,__TT>& ti) {
0187     return get_helper<__N-1>::get(ti.tail);
0188 }
0189 };
0190 
0191 template<>
0192 struct get_helper<0> {
0193 template<typename __HT, typename __TT>
0194 inline static typename component<0, cons<__HT,__TT> >::type& get(cons<__HT,__TT>& ti) {
0195     return ti.head;
0196 }
0197 template<typename __HT, typename __TT>
0198 inline static typename component<0, cons<__HT,__TT> >::type const& get(const cons<__HT,__TT>& ti) {
0199     return ti.head;
0200 }
0201 };
0202 
0203 // traits adaptor
0204 template <typename __T0, typename __T1, typename __T2, typename __T3, typename __T4 __TBB_TYPENAME_T_PACK>
0205 struct tuple_traits {
0206     typedef cons <__T0, typename tuple_traits<__T1, __T2, __T3, __T4 __TBB_T_PACK , null_type>::U > U;
0207 };
0208 
0209 template <typename __T0>
0210 struct tuple_traits<__T0, null_type, null_type, null_type, null_type __TBB_NULL_TYPE_PACK > {
0211     typedef cons<__T0, null_type> U;
0212 };
0213 
0214 template<>
0215 struct tuple_traits<null_type, null_type, null_type, null_type, null_type __TBB_NULL_TYPE_PACK > {
0216     typedef null_type U;
0217 };
0218 
0219 
0220 // core cons defs
0221 template <typename __HT, typename __TT>
0222 struct cons{
0223 
0224     typedef __HT head_type;
0225     typedef __TT tail_type;
0226 
0227     head_type head;
0228     tail_type tail;
0229 
0230     static const int length = 1 + tail_type::length;
0231 
0232     // default constructors
0233     explicit cons() : head(), tail() { }
0234 
0235     // non-default constructors
0236     cons(head_type& h, const tail_type& t) : head(h), tail(t) { }
0237 
0238     template <typename __T0, typename __T1, typename __T2, typename __T3, typename __T4 __TBB_TYPENAME_T_PACK >
0239     cons(const __T0& t0, const __T1& t1, const __T2& t2, const __T3& t3, const __T4& t4 __TBB_CONST_REF_T_PARAM_PACK) :
0240         head(t0), tail(t1, t2, t3, t4 __TBB_T_PARAM_LIST_PACK, cnull()) { }
0241 
0242     template <typename __T0, typename __T1, typename __T2, typename __T3, typename __T4 __TBB_TYPENAME_T_PACK >
0243     cons(__T0& t0, __T1& t1, __T2& t2, __T3& t3, __T4& t4 __TBB_REF_T_PARAM_PACK) :
0244         head(t0), tail(t1, t2, t3, t4 __TBB_T_PARAM_LIST_PACK , cnull()) { }
0245 
0246     template <typename __HT1, typename __TT1>
0247     cons(const cons<__HT1,__TT1>& other) : head(other.head), tail(other.tail) { }
0248 
0249     cons& operator=(const cons& other) { head = other.head; tail = other.tail; return *this; }
0250 
0251     friend bool operator==(const cons& me, const cons& other) {
0252         return me.head == other.head && me.tail == other.tail;
0253     }
0254     friend bool operator<(const cons& me, const cons& other)  {
0255         return me.head < other.head || (!(other.head < me.head) && me.tail < other.tail);
0256     }
0257     friend bool operator>(const cons& me, const cons& other)  { return other<me; }
0258     friend bool operator!=(const cons& me, const cons& other) { return !(me==other); }
0259     friend bool operator>=(const cons& me, const cons& other) { return !(me<other); }
0260     friend bool operator<=(const cons& me, const cons& other) { return !(me>other); }
0261 
0262     template<typename __HT1, typename __TT1>
0263     friend bool operator==(const cons<__HT,__TT>& me, const cons<__HT1,__TT1>& other) {
0264         return me.head == other.head && me.tail == other.tail;
0265     }
0266 
0267     template<typename __HT1, typename __TT1>
0268     friend bool operator<(const cons<__HT,__TT>& me, const cons<__HT1,__TT1>& other) {
0269         return me.head < other.head || (!(other.head < me.head) && me.tail < other.tail);
0270     }
0271 
0272     template<typename __HT1, typename __TT1>
0273     friend bool operator>(const cons<__HT,__TT>& me, const cons<__HT1,__TT1>& other) { return other<me; }
0274 
0275     template<typename __HT1, typename __TT1>
0276     friend bool operator!=(const cons<__HT,__TT>& me, const cons<__HT1,__TT1>& other) { return !(me==other); }
0277 
0278     template<typename __HT1, typename __TT1>
0279     friend bool operator>=(const cons<__HT,__TT>& me, const cons<__HT1,__TT1>& other) { return !(me<other); }
0280 
0281     template<typename __HT1, typename __TT1>
0282     friend bool operator<=(const cons<__HT,__TT>& me, const cons<__HT1,__TT1>& other) { return !(me>other); }
0283 
0284 
0285 };  // cons
0286 
0287 
0288 template <typename __HT>
0289 struct cons<__HT,null_type> {
0290 
0291     typedef __HT head_type;
0292     typedef null_type tail_type;
0293 
0294     head_type head;
0295 
0296     static const int length = 1;
0297 
0298     // default constructor
0299     cons() : head() { /*std::cout << "default constructor 1\n";*/ }
0300 
0301     cons(const null_type&, const null_type&, const null_type&, const null_type&, const null_type& __TBB_CONST_NULL_REF_PACK) : head() { /*std::cout << "default constructor 2\n";*/ }
0302 
0303     // non-default constructor
0304     template<typename __T1>
0305     cons(__T1& t1, const null_type&, const null_type&, const null_type&, const null_type& __TBB_CONST_NULL_REF_PACK) : head(t1) { /*std::cout << "non-default a1, t1== " << t1 << "\n";*/}
0306 
0307     cons(head_type& h, const null_type& = null_type() ) : head(h) { }
0308     cons(const head_type& t0, const null_type&, const null_type&, const null_type&, const null_type& __TBB_CONST_NULL_REF_PACK) : head(t0) { }
0309 
0310     // converting constructor
0311     template<typename __HT1>
0312     cons(__HT1 h1, const null_type&, const null_type&, const null_type&, const null_type& __TBB_CONST_NULL_REF_PACK) : head(h1) { }
0313 
0314     // copy constructor
0315     template<typename __HT1>
0316     cons( const cons<__HT1, null_type>& other) : head(other.head) { }
0317 
0318     // assignment operator
0319     cons& operator=(const cons& other) { head = other.head; return *this; }
0320 
0321     friend bool operator==(const cons& me, const cons& other) { return me.head == other.head; }
0322     friend bool operator<(const cons& me, const cons& other) { return me.head < other.head; }
0323     friend bool operator>(const cons& me, const cons& other) { return other<me; }
0324     friend bool operator!=(const cons& me, const cons& other) {return !(me==other); }
0325     friend bool operator<=(const cons& me, const cons& other) {return !(me>other); }
0326     friend bool operator>=(const cons& me, const cons& other) {return !(me<other); }
0327 
0328     template<typename __HT1>
0329     friend bool operator==(const cons<__HT,null_type>& me, const cons<__HT1,null_type>& other) {
0330         return me.head == other.head;
0331     }
0332 
0333     template<typename __HT1>
0334     friend bool operator<(const cons<__HT,null_type>& me, const cons<__HT1,null_type>& other) {
0335         return me.head < other.head;
0336     }
0337 
0338     template<typename __HT1>
0339     friend bool operator>(const cons<__HT,null_type>& me, const cons<__HT1,null_type>& other) { return other<me; }
0340 
0341     template<typename __HT1>
0342     friend bool operator!=(const cons<__HT,null_type>& me, const cons<__HT1,null_type>& other) { return !(me==other); }
0343 
0344     template<typename __HT1>
0345     friend bool operator<=(const cons<__HT,null_type>& me, const cons<__HT1,null_type>& other) { return !(me>other); }
0346 
0347     template<typename __HT1>
0348     friend bool operator>=(const cons<__HT,null_type>& me, const cons<__HT1,null_type>& other) { return !(me<other); }
0349 
0350 };  // cons
0351 
0352 template <>
0353 struct cons<null_type,null_type> { typedef null_type tail_type; static const int length = 0; };
0354 
0355 // wrapper for default constructor
0356 template<typename __T>
0357 inline const __T wrap_dcons(__T*) { return __T(); }
0358 
0359 } // namespace internal
0360 
0361 // tuple definition
0362 template<typename __T0, typename __T1, typename __T2, typename __T3, typename __T4 __TBB_TYPENAME_T_PACK >
0363 class __TBB_DEPRECATED_IN_VERBOSE_MODE tuple : public internal::tuple_traits<__T0, __T1, __T2, __T3, __T4 __TBB_T_PACK >::U {
0364     // friends
0365     template <typename __T> friend class tuple_size;
0366     template<int __N, typename __T> friend struct tuple_element;
0367 
0368     // stl components
0369     typedef tuple<__T0,__T1,__T2,__T3,__T4 __TBB_T_PACK > value_type;
0370     typedef value_type *pointer;
0371     typedef const value_type *const_pointer;
0372     typedef value_type &reference;
0373     typedef const value_type &const_reference;
0374     typedef size_t size_type;
0375 
0376     typedef typename internal::tuple_traits<__T0,__T1,__T2,__T3, __T4 __TBB_T_PACK >::U my_cons;
0377 
0378 public:
0379     __TBB_DEPRECATED_IN_VERBOSE_MODE tuple(const __T0& t0=internal::wrap_dcons((__T0*)NULL)
0380           ,const __T1& t1=internal::wrap_dcons((__T1*)NULL)
0381           ,const __T2& t2=internal::wrap_dcons((__T2*)NULL)
0382           ,const __T3& t3=internal::wrap_dcons((__T3*)NULL)
0383           ,const __T4& t4=internal::wrap_dcons((__T4*)NULL)
0384 #if __TBB_VARIADIC_MAX >= 6
0385           ,const __T5& t5=internal::wrap_dcons((__T5*)NULL)
0386 #if __TBB_VARIADIC_MAX >= 7
0387           ,const __T6& t6=internal::wrap_dcons((__T6*)NULL)
0388 #if __TBB_VARIADIC_MAX >= 8
0389           ,const __T7& t7=internal::wrap_dcons((__T7*)NULL)
0390 #if __TBB_VARIADIC_MAX >= 9
0391           ,const __T8& t8=internal::wrap_dcons((__T8*)NULL)
0392 #if __TBB_VARIADIC_MAX >= 10
0393           ,const __T9& t9=internal::wrap_dcons((__T9*)NULL)
0394 #endif
0395 #endif
0396 #endif
0397 #endif
0398 #endif
0399           ) :
0400         my_cons(t0,t1,t2,t3,t4 __TBB_T_PARAM_LIST_PACK) { }
0401 
0402     template<int __N>
0403     struct internal_tuple_element {
0404         typedef typename internal::component<__N,my_cons>::type type;
0405     };
0406 
0407     template<int __N>
0408     typename internal_tuple_element<__N>::type& get() { return internal::get_helper<__N>::get(*this); }
0409 
0410     template<int __N>
0411     typename internal_tuple_element<__N>::type const& get() const { return internal::get_helper<__N>::get(*this); }
0412 
0413     template<typename __U1, typename __U2>
0414     tuple& operator=(const internal::cons<__U1,__U2>& other) {
0415         my_cons::operator=(other);
0416         return *this;
0417     }
0418 
0419     template<typename __U1, typename __U2>
0420     tuple& operator=(const std::pair<__U1,__U2>& other) {
0421         // __TBB_ASSERT(tuple_size<value_type>::value == 2, "Invalid size for pair to tuple assignment");
0422         this->head = other.first;
0423         this->tail.head = other.second;
0424         return *this;
0425     }
0426 
0427     friend bool operator==(const tuple& me, const tuple& other) {return static_cast<const my_cons &>(me)==(other);}
0428     friend bool operator<(const tuple& me,  const tuple& other) {return static_cast<const my_cons &>(me)<(other);}
0429     friend bool operator>(const tuple& me,  const tuple& other) {return static_cast<const my_cons &>(me)>(other);}
0430     friend bool operator!=(const tuple& me, const tuple& other) {return static_cast<const my_cons &>(me)!=(other);}
0431     friend bool operator>=(const tuple& me, const tuple& other) {return static_cast<const my_cons &>(me)>=(other);}
0432     friend bool operator<=(const tuple& me, const tuple& other) {return static_cast<const my_cons &>(me)<=(other);}
0433 
0434 };  // tuple
0435 
0436 // empty tuple
0437 template<>
0438 class __TBB_DEPRECATED_IN_VERBOSE_MODE tuple<null_type, null_type, null_type, null_type, null_type __TBB_NULL_TYPE_PACK > : public null_type {
0439 };
0440 
0441 // helper classes
0442 
0443 template < typename __T>
0444 class tuple_size {
0445 public:
0446     static const size_t value = 1 + tuple_size<typename __T::tail_type>::value;
0447 };
0448 
0449 template <>
0450 class tuple_size<tuple<> > {
0451 public:
0452     static const size_t value = 0;
0453 };
0454 
0455 template <>
0456 class tuple_size<null_type> {
0457 public:
0458     static const size_t value = 0;
0459 };
0460 
0461 template<int __N, typename __T>
0462 struct tuple_element {
0463     typedef typename internal::component<__N, typename __T::my_cons>::type type;
0464 };
0465 
0466 template<int __N, typename __T0, typename __T1, typename __T2, typename __T3, typename __T4 __TBB_TYPENAME_T_PACK >
0467 inline static typename tuple_element<__N,tuple<__T0,__T1,__T2,__T3,__T4 __TBB_T_PACK > >::type&
0468     get(tuple<__T0,__T1,__T2,__T3,__T4 __TBB_T_PACK >& t) { return internal::get_helper<__N>::get(t); }
0469 
0470 template<int __N, typename __T0, typename __T1, typename __T2, typename __T3, typename __T4 __TBB_TYPENAME_T_PACK >
0471 inline static typename tuple_element<__N,tuple<__T0,__T1,__T2,__T3,__T4 __TBB_T_PACK > >::type const&
0472     get(const tuple<__T0,__T1,__T2,__T3,__T4 __TBB_T_PACK >& t) { return internal::get_helper<__N>::get(t); }
0473 
0474 }  // interface5
0475 } // tbb
0476 
0477 #if !__TBB_CPP11_TUPLE_PRESENT
0478 namespace tbb {
0479     namespace flow {
0480         using tbb::interface5::tuple;
0481         using tbb::interface5::tuple_size;
0482         using tbb::interface5::tuple_element;
0483         using tbb::interface5::get;
0484     }
0485 }
0486 #endif
0487 
0488 #undef __TBB_T_PACK
0489 #undef __TBB_U_PACK
0490 #undef __TBB_TYPENAME_T_PACK
0491 #undef __TBB_TYPENAME_U_PACK
0492 #undef __TBB_NULL_TYPE_PACK
0493 #undef __TBB_REF_T_PARAM_PACK
0494 #undef __TBB_CONST_REF_T_PARAM_PACK
0495 #undef __TBB_T_PARAM_LIST_PACK
0496 #undef __TBB_CONST_NULL_REF_PACK
0497 
0498 #include "../internal/_warning_suppress_disable_notice.h"
0499 #undef __TBB_tuple_H_include_area
0500 
0501 #endif /* __TBB_tuple_H */