1

Using the rangev3 library I can do this:

  auto march = view::iota(1,32)
              | view::transform(
                [](int i){return date(1995, greg::Mar, i);
                });

giving me the dates in the march of 1995:

1995-Mar-01
...
1995-Mar-31

Is there a way to do this in a syntax even closer to pythons:

[date(1995, Mar, i) for i in range(32)] 

In particular I feel beginning with the date/function aids the readability of the code.

1 Answers1

0

The closest you are going to get is by using variadics:

namespace detail {
  template <std::size_t ...Is>
  std::vector<date> generate(std::index_sequence<Is...>) {
    return {date(1995, greg::Mar, Is + 1)...}; // almost like Python
  }
}

std::vector<date> generate() {
  return detail::generate(std::make_index_sequence<32>());
}

But now you are not using ranges and you have to define two separate functions.

Rakete1111
  • 47,013
  • 16
  • 123
  • 162