# CartesianIndices syntax

**URL:** <https://discourse.julialang.org/t/cartesianindices-syntax/22970>\
**Category:** General Usage\
**Tags:** indexing\
**Created:** [April 9, 2019, 7:25pm UTC](https://discourse.julialang.org/t/cartesianindices-syntax/22970 "2019-04-09T19:25:55Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 9, 2019, 8:46pm UTC](https://discourse.julialang.org/t/cartesianindices-syntax/22970/3 "2019-04-09T20:46:27Z")

</div>

The key is that @Pier seems to be after peak performance — and reducing all allocations at all costs. Typically you wouldn’t need `CartesianIndices` or `CartesianIndex` at all. Just using regular old indexed assignment with a view would be enough.

```julia
dest[2:4, [2,5]] = @view src[2:4, [2,5]]

```

That will work and be reasonably fast… but it’ll allocate a small wrapper for the view and won’t be quite as fast as just writing out the loops manually.

Someone else just asked for this capability a day or two ago: [Support CartesianIndices with Arrays and other iterables, not just ranges (alternative?) - #8 by mbauman](https://discourse.julialang.org/t/support-cartesianindices-with-arrays-and-other-iterables-not-just-ranges-alternative/22812/8). I suppose we could keep the specializations for the all-UnitRange case and just allow it to behave like `map(CartesianIndex, Iterators.product(...))` in other cases.

---

_[View the full topic](https://discourse.julialang.org/t/cartesianindices-syntax/22970)._
