Skip to content

File for_in_range.h

File List > code_source > templat > include > TempLat > util > rangeiteration > for_in_range.h

Go to the documentation of this file

#ifndef TEMPLAT_UTIL_RANGEITERATION_FOR_IN_RANGE_H
#define TEMPLAT_UTIL_RANGEITERATION_FOR_IN_RANGE_H

/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
   Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
   Released under the MIT license, see LICENSE.md. */

// File info: Main contributor(s): Adrien Florio, Year: 2019

#include "TempLat/util/foreach.h"
#include "TempLat/util/rangeiteration/taglist.h"

namespace TempLat
{

  template <int i, int j> struct ForRangeHelper {

    template <typename F> static void run(F &&f)
    {
      TagList<i, j - 1> tg;
      for_each(tg.tags, f);
    }
  };
  template <int i> struct ForRangeHelper<i, 0> {

    template <typename F> static void run(F &&f) {}
  };

  template <int i, int j, typename F> void for_in_range(F &&f)
  {
    // TagList<i,j-1> tg;
    // for_each(tg.tags,f);
    ForRangeHelper<i, j>::run(f);
  }

#define ForLoop(i, start, end, expr) for_in_range<start, end + 1>([&](auto i) { expr; })

} // namespace TempLat

#endif