[docs] Fix style and typo in HowToSetUpLLVMStyleRTTI.rst after D126943

This commit is contained in:
Fangrui Song 2022-06-06 12:41:21 -07:00
parent cca662b849
commit f9e9037c86
1 changed files with 9 additions and 12 deletions

View File

@ -513,9 +513,8 @@ we can use some provided cast traits like so:
template <typename T>
struct CastInfo<T, SomeValue>
: public CastIsPossible<T, SomeValue>,
public NullableValueCastFailed<T>,
public DefaultDoCastIfPossible<T, SomeValue, CastInfo<T, SomeValue>> {
: CastIsPossible<T, SomeValue>, NullableValueCastFailed<T>,
DefaultDoCastIfPossible<T, SomeValue, CastInfo<T, SomeValue>> {
static T doCast(SomeValue v) {
return T(v.getPointer());
}
@ -530,9 +529,8 @@ that type from a char pointer type. So what we would do in that case is:
template <typename T>
struct CastInfo<SomeValue, T *>
: public NullableValueCastFailed<SomeValue>,
public DefaultDoCastIfPossible<SomeValue, T *,
CastInfo<SomeValue, T *>> {
: NullableValueCastFailed<SomeValue>,
DefaultDoCastIfPossible<SomeValue, T *, CastInfo<SomeValue, T *>> {
static bool isPossible(const T *t) {
return std::is_same<T, char>::value;
}
@ -552,8 +550,7 @@ In those cases, you probably want something like this:
.. code-block:: c++
template <typename T>
struct CastInfo<T, SomeValue>
: public OptionalValueCast<T, SomeValue> {};
struct CastInfo<T, SomeValue> : OptionalValueCast<T, SomeValue> {};
That cast trait requires that ``T`` is constructible from ``const SomeValue &``
but it enables casting like so:
@ -563,7 +560,7 @@ but it enables casting like so:
SomeValue someVal = ...;
Optional<AnotherValue> valOr = dyn_cast<AnotherValue>(someVal);
With the ``_is_present`` variants, you can even do optional chaining like this:
With the ``_if_present`` variants, you can even do optional chaining like this:
.. code-block:: c++