is, as, Casting
is (Type Query)
See Cpp2 is:
obj is Int(i.e. a type)objPtr is T*instead ofdynamic_cast<T*>(objPtr) != NullPtrobj is cilia::Array(i.e. a template)obj is cilia::Integer(i.e. a concept)
TODO Also support value query?
as
See Cpp2 as
obj as Tinstead ofT(obj)objPtr as T*instead ofdynamic_cast<T*>(objPtr)- With
Variant vwhere T is one alternative:
v as Tinstead ofstd::get<T>(v) - With
Any a:
a as Tinstead ofstd::any_cast<T>(a) - With
Optional<T> o:
o as Tinstead ofo.value()
Constructor Casting
Float(3)- Casting via constructor is
explicitby default,implicitas option. - No classic C-style casting:
(Float) 3
Classical C++ Casts
All of these also work for smart pointers (T^, T+, T-), replacing .std::*_pointer_cast
staticCastTo<T>(...)instead ofstatic_cast<T>(...)dynamicCastTo<T>(...)instead ofdynamic_cast<T>(...)- But typically
objPtr as T*is preferred.
- But typically
castToMutable<T>(...)instead of,const_cast<T>(...)- typically used as
castToMutable(...), as the type is inferred.
- typically used as
reinterpretCastTo<T>(...)instead ofreinterpret_cast<T>(...)castTo<T>(...)?- A general, safe cast, i.e. like
as, but in function syntax.
- A general, safe cast, i.e. like
- Other casts of the C++ standard library (and GSL):
bitCastTo<T>(...)instead ofstd::bit_cast<T>(...)anyCastTo<T>(a)instead ofstd::any_cast<T>(a)- But typically
a as Tis preferred.
- But typically
durationCastTo<T>(d)instead ofstd::chrono::duration_cast<T>(d)timePointCastTo<T>(t)instead ofstd::chrono::time_point_cast<T>(t)narrowCastTo<T>(...)instead of(unchecked)gsl::narrow_cast<T>(...)narrowTo<T>(...)instead of(checked)gsl::narrow<T>(...)