package main

import "fmt"

// section: main
func main() {
	// Source slice with 3 elements
	source := []string{"John", "Paul", "George"}
	fmt.Println("Source slice:", source)
	fmt.Println()

	// Variation 1: Copy to a zero-size slice
	// When the destination has no capacity, nothing is copied
	zeroSize := []string{}
	n := copy(zeroSize, source)
	fmt.Printf("Zero size slice (len=%d, cap=%d):\n", len(zeroSize), cap(zeroSize))
	fmt.Printf("  Copied %d elements\n", n)
	fmt.Printf("  Result: %v\n", zeroSize)
	fmt.Println()

	// Variation 2: Copy to a slice of size 3 (same size as source)
	// When the destination has the same size, all elements are copied
	sizeThree := make([]string, 3)
	n = copy(sizeThree, source)
	fmt.Printf("Size 3 slice (len=%d, cap=%d):\n", len(sizeThree), cap(sizeThree))
	fmt.Printf("  Copied %d elements\n", n)
	fmt.Printf("  Result: %v\n", sizeThree)
	fmt.Println()

	// Variation 3: Copy to a slice of size 10 (larger than source)
	// When the destination is larger, only source elements are copied
	// The remaining destination elements remain as zero values
	sizeTen := make([]string, 10)
	n = copy(sizeTen, source)
	fmt.Printf("Size 10 slice (len=%d, cap=%d):\n", len(sizeTen), cap(sizeTen))
	fmt.Printf("  Copied %d elements\n", n)
	fmt.Printf("  Result: %v\n", sizeTen)
	fmt.Println()

	// Key takeaway: copy() returns the number of elements copied,
	// which is the minimum of len(dst) and len(src)
	fmt.Println("Key Point: copy() only copies min(len(dst), len(src)) elements")
}

// section: main
