blob: c0496c58a0186fff3f2dcb70222b3b9ca728783b [file] [log] [blame]
Brian Silverman61378172018-08-04 23:37:59 -07001// Copyright 2002 The Trustees of Indiana University.
2
3// Use, modification and distribution is subject to the Boost Software
4// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7// Boost.MultiArray Library
8// Authors: Ronald Garcia
9// Jeremy Siek
10// Andrew Lumsdaine
11// See http://www.boost.org/libs/multi_array for documentation.
12
13#ifndef FOR_EACH_HPP
14#define FOR_EACH_HPP
15
16//
17// for_each.hpp - Writing an algorithm to transform each element of
18// a multi_array
19//
20
21#include "boost/type.hpp"
22
23template <typename Array, typename Element, typename Functor>
24void for_each (const boost::type<Element>& type_dispatch,
25 Array A, Functor& xform) {
26 for_each(type_dispatch,A.begin(),A.end(),xform);
27}
28
29template <typename Element, typename Functor>
30void for_each (const boost::type<Element>&,Element& Val, Functor& xform) {
31 Val = xform(Val);
32}
33
34template <typename Element, typename Iterator, typename Functor>
35void for_each (const boost::type<Element>& type_dispatch,
36 Iterator begin, Iterator end,
37 Functor& xform) {
38 while (begin != end) {
39 for_each(type_dispatch,*begin,xform);
40 ++begin;
41 }
42}
43
44
45template <typename Array, typename Functor>
46void for_each (Array& A, Functor xform) {
47 // Dispatch to the proper function
48 for_each(boost::type<typename Array::element>(),A.begin(),A.end(),xform);
49}
50
51
52#endif // FOR_EACH_HPP