<commit_before>// ======================================================================== //
// Copyright 2009-2018 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#pragma once

#include "parallel_for.h"

#include <array>
#include <vector>

namespace ospcommon {
  namespace tasking {

    template<typename ELEMENT_T, typename TASK_T>
    inline void parallel_foreach(std::vector<ELEMENT_T> &v, TASK_T&& f)
    {
      parallel_for(v.size(), [&](size_t i){
        f(v[i]);
      });
    }

    template<typename ELEMENT_T, typename TASK_T>
    inline void parallel_foreach(const std::vector<ELEMENT_T> &v, TASK_T&& f)
    {
      parallel_for(v.size(), [&](size_t i){
        f(v[i]);
      });
    }

    template<typename ELEMENT_T, size_t N, typename TASK_T>
    inline void parallel_foreach(std::array<ELEMENT_T, N> &v, TASK_T&& f)
    {
      parallel_for(N, [&](size_t i){
        f(v[i]);
      });
    }

    template<typename ELEMENT_T, size_t N, typename TASK_T>
    inline void parallel_foreach(const std::array<ELEMENT_T, N> &v, TASK_T&& f)
    {
      parallel_for(N, [&](size_t i){
        f(v[i]);
      });
    }

  } // ::ospcommon::tasking
} //::ospcommon
<commit_msg>more general versions of parallel_foreach()<commit_after>// ======================================================================== //
// Copyright 2009-2018 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#pragma once

#include "parallel_for.h"

#include <iterator>

namespace ospcommon {
  namespace tasking {

    template<typename ITERATOR_T, typename TASK_T>
    inline void parallel_foreach(ITERATOR_T begin, ITERATOR_T end, TASK_T&& f)
    {
      using ITERATOR_KIND =
          typename std::iterator_traits<ITERATOR_T>::iterator_category;

      static_assert(std::is_same<ITERATOR_KIND,
                                 std::random_access_iterator_tag>::value,
                    "ospcommon::tasking::parallel_foreach() requires random-"
                    "access iterators!");

      const size_t count = std::distance(begin, end);
      auto *v = &(*begin);

      parallel_for(count, [&](size_t i){ f(v[i]); });
    }

    template<typename CONTAINER_T, typename TASK_T>
    inline void parallel_foreach(CONTAINER_T &&c, TASK_T&& f)
    {
      parallel_foreach(std::begin(c), std::end(c), std::forward<TASK_T>(f));
    }

  } // ::ospcommon::tasking
} //::ospcommon

{'fraction_non_alphanumeric': 0.16914080071974807, 'fraction_numerical': 0.005398110661268556, 'mean_word_length': 1.6660671462829737, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2132792', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1066, 'n_words': 308}