logo
  • 教程列表
  • SO官方文檔
  • IOTA
    • 在表示式中使用 iota
    • 簡單使用 iota
    • 在表示式列表中使用 iota
    • 跳過值
    • 在位掩碼中使用 iota
    • 在 const 中使用 iota
  1. StackOverflow 文件
  2. Go 教程
  3. IOTA
  4. 在表示式列表中使用 iota

在表示式列表中使用 iota

Created: November-22, 2018

因為 iota 在每個 ConstSpec 之後遞增 ,所以同一表示式列表中的值將具有相同的 iota 值:

const (
    bit0, mask0 = 1 << iota, 1<<iota - 1  // bit0 == 1, mask0 == 0
    bit1, mask1                           // bit1 == 2, mask1 == 1
    _, _                                  // skips iota == 2
    bit3, mask3                           // bit3 == 8, mask3 == 7
)

此示例取自 Go Spec (CC-BY 3.0)。

  • 跳過值
  • 簡單使用 iota

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明