Skip to main content

Mojo struct

ComptimeInt

struct ComptimeInt[val: Int]

Compile-time known index value.

Parameters

  • val (Int): The compile-time integer value.

Implemented traits

AnyType, CoordLike, Copyable, Defaultable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, RegisterPassable, TrivialRegisterPassable, Writable

comptime members

DTYPE

comptime DTYPE = DType.int

The data type (int for compile-time integers).

is_static_value

comptime is_static_value = True

True, indicating this is a compile-time known value.

is_tuple

comptime is_tuple = False

True if this is a tuple type (Coord), False for scalar values.

is_value

comptime is_value = True

True if this is a scalar value, False for tuple types.

ParamListType

comptime ParamListType = ComptimeInt[val]

The variadic element types (Self for scalar types).

static_value

comptime static_value = val

The compile-time value.

Methods

__init__

__init__() -> Self

Initialize a compile-time integer with the specified value.

__len__

static __len__() -> Int

Get the length (always 1 for scalar types).

Returns:

Int: Always returns 1.

write_to

write_to(self, mut writer: T)

Write this compile-time integer to a writer.

Args:

  • writer (T): The writer to write to.

write_repr_to

write_repr_to(self, mut writer: T)

Write the repr of this compile-time integer to a writer.

Args:

  • writer (T): The writer to write to.

product

product(self) -> Int

Calculate the product (returns the value for scalar types).

Returns:

Int: The integer value.

sum

sum(self) -> Int

Calculate the sum (returns the value for scalar types).

Returns:

Int: The integer value.

value

value(self) -> Int

Get the integer value.

Returns:

Int: The compile-time integer value.

tuple

tuple(var self) -> Coord[*ComptimeInt[val].ParamListType]

Get as a tuple (not valid for ComptimeInt).

Returns:

Coord: Never returns; aborts at compile time.

Was this page helpful?