_range_iterator.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Copyright (c) 2005-2020 Intel Corporation
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #ifndef __TBB_range_iterator_H
  14. #define __TBB_range_iterator_H
  15. #include "../tbb_stddef.h"
  16. #if __TBB_CPP11_STD_BEGIN_END_PRESENT && __TBB_CPP11_AUTO_PRESENT && __TBB_CPP11_DECLTYPE_PRESENT
  17. #include <iterator>
  18. #endif
  19. namespace tbb {
  20. // iterators to first and last elements of container
  21. namespace internal {
  22. #if __TBB_CPP11_STD_BEGIN_END_PRESENT && __TBB_CPP11_AUTO_PRESENT && __TBB_CPP11_DECLTYPE_PRESENT
  23. using std::begin;
  24. using std::end;
  25. template<typename Container>
  26. auto first(Container& c)-> decltype(begin(c)) {return begin(c);}
  27. template<typename Container>
  28. auto first(const Container& c)-> decltype(begin(c)) {return begin(c);}
  29. template<typename Container>
  30. auto last(Container& c)-> decltype(begin(c)) {return end(c);}
  31. template<typename Container>
  32. auto last(const Container& c)-> decltype(begin(c)) {return end(c);}
  33. #else
  34. template<typename Container>
  35. typename Container::iterator first(Container& c) {return c.begin();}
  36. template<typename Container>
  37. typename Container::const_iterator first(const Container& c) {return c.begin();}
  38. template<typename Container>
  39. typename Container::iterator last(Container& c) {return c.end();}
  40. template<typename Container>
  41. typename Container::const_iterator last(const Container& c) {return c.end();}
  42. #endif
  43. template<typename T, size_t size>
  44. T* first(T (&arr) [size]) {return arr;}
  45. template<typename T, size_t size>
  46. T* last(T (&arr) [size]) {return arr + size;}
  47. } //namespace internal
  48. } //namespace tbb
  49. #endif // __TBB_range_iterator_H