Skip to main content

Mojo struct

ComptimeInt

@register_passable(trivial) 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

__copy_ctor_is_trivial

comptime __copy_ctor_is_trivial = True

__del__is_trivial

comptime __del__is_trivial = True

__move_ctor_is_trivial

comptime __move_ctor_is_trivial = True

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.

static_value

comptime static_value = val

The compile-time value.

VariadicType

comptime VariadicType = ComptimeInt[val]

The variadic element types (Self for scalar types).

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.

__repr__

__repr__(self) -> String

Get the string representation of this compile-time integer.

Returns:

String: A string in the format "ComptimeIntvalue".

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].VariadicType]

Get as a tuple (not valid for ComptimeInt).

Returns:

Coord: Never returns; aborts at compile time.

Was this page helpful?