# Why this error in copyto!?

**URL:** https://discourse.julialang.org/t/why-this-error-in-copyto/17658
**Category:** New to Julia
**Tags:** question
**Created:** [November 17, 2018, 9:39pm UTC](https://discourse.julialang.org/t/why-this-error-in-copyto/17658 "2018-11-17T21:39:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![leiteiro](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@leiteiro](https://discourse.julialang.org/u/leiteiro)
#### Post date: [November 17, 2018, 9:39pm UTC](https://discourse.julialang.org/t/why-this-error-in-copyto/17658/1 "2018-11-17T21:39:07Z")

</div>

Consider the well known Squares

```
struct Squares count::Int end
Base.iterate(S::Squares, state=START) = state > S.count ? nothing : (state*state, state+1)
Base.length(S::Squares) = S.count

```

and

```
Enumerate(iter, start, step) = zip(Iterators.countfrom(start, step), iter)
Enumerate(Squares(6), 0, 2) |> println ∘ collect

```

If I choose START = 1 in Squares then I get

```
Tuple{Int64,Any}[(0, 1), (2, 4), (4, 9), (6, 16), (8, 25), (10, 36)]

```

If I choose START = 0 then I get

```
ERROR: LoadError: ArgumentError: destination has fewer elements 
than required. Stacktrace: [1] copyto!(...) at .\abstractarray.jl:665

```

Why this different behavior?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [November 18, 2018, 7:23am UTC](https://discourse.julialang.org/t/why-this-error-in-copyto/17658/2 "2018-11-18T07:23:59Z")

</div>

> [@leiteiro](#):
>
> If I choose START = 1 in Squares then I get

I think you misunderstand the iteration protocol. Starting from `state = 0` will make `length(::Squares)` inconsistent with what the iterator does, hence the error.
