mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope. Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
86 lines
1.8 KiB
C
86 lines
1.8 KiB
C
/**
|
|
* @require Type.is_ordered : "The type must be ordered"
|
|
**/
|
|
module std::collections::range(<Type>);
|
|
import std::io;
|
|
|
|
struct Range (Printable)
|
|
{
|
|
Type start;
|
|
Type end;
|
|
}
|
|
|
|
fn usz Range.len(&self) @operator(len)
|
|
{
|
|
if (self.end < self.start) return 0;
|
|
return (usz)(self.end - self.start) + 1;
|
|
}
|
|
|
|
fn bool Range.contains(&self, Type value) @inline
|
|
{
|
|
return value >= self.start && value <= self.end;
|
|
}
|
|
|
|
/**
|
|
* @require index < self.len() : "Can't index into an empty range"
|
|
**/
|
|
fn Type Range.get(&self, usz index) @operator([])
|
|
{
|
|
return (Type)(self.start + (usz)index);
|
|
}
|
|
|
|
fn String Range.to_new_string(&self, Allocator allocator = allocator::heap()) @dynamic
|
|
{
|
|
return string::new_format("[%s..%s]", self.start, self.end, .allocator = allocator);
|
|
}
|
|
|
|
fn String Range.to_tstring(&self)
|
|
{
|
|
return self.to_new_string(allocator::temp());
|
|
}
|
|
|
|
fn usz! Range.to_format(&self, Formatter* formatter) @dynamic
|
|
{
|
|
return formatter.printf("[%s..%s]", self.start, self.end)!;
|
|
}
|
|
|
|
struct ExclusiveRange (Printable)
|
|
{
|
|
Type start;
|
|
Type end;
|
|
}
|
|
|
|
fn usz ExclusiveRange.len(&self) @operator(len)
|
|
{
|
|
if (self.end < self.start) return 0;
|
|
return (usz)(self.end - self.start);
|
|
}
|
|
|
|
fn bool ExclusiveRange.contains(&self, Type value) @inline
|
|
{
|
|
return value >= self.start && value < self.end;
|
|
}
|
|
|
|
fn usz! ExclusiveRange.to_format(&self, Formatter* formatter) @dynamic
|
|
{
|
|
return formatter.printf("[%s..<%s]", self.start, self.end)!;
|
|
}
|
|
|
|
fn String ExclusiveRange.to_new_string(&self, Allocator allocator = allocator::heap()) @dynamic
|
|
{
|
|
return string::new_format("[%s..<%s]", self.start, self.end, .allocator = allocator);
|
|
}
|
|
|
|
fn String ExclusiveRange.to_tstring(&self)
|
|
{
|
|
return self.to_new_string(allocator::temp());
|
|
}
|
|
|
|
/**
|
|
* @require index < self.len() : "Can't index into an empty range"
|
|
**/
|
|
fn Type ExclusiveRange.get(&self, usz index) @operator([])
|
|
{
|
|
return (Type)(self.start + index);
|
|
}
|