Standard library / reflect

reflect.Value.Slice3()

Returns a three-index slice view with capacity limited by the third index; it does not work on strings. Expected stdout: '1 2\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) Slice3(i, j, k int) Value

Parameters & Attributes

NameTypeDescription
iintZero-based index, or the input interface value for TypeOf and ValueOf.
jintExclusive upper index.
kintExclusive capacity bound for three-index slicing.

Return Value

Value

Returns a three-index slice view with capacity limited by the third index; it does not work on strings.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  s := reflect.ValueOf([]int{1, 2, 3})  r := s.Slice3(0, 1, 2)  fmt.Println(r.Len(), r.Cap())}
Go Reference