Boost logo

Boost :

Subject: Re: [boost] Nasty compile time reflection and iteration for POD types using C++14 without macro
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2016-03-25 02:39:11


2016-03-25 2:03 GMT+03:00 Klemens Morgenstern <klemens.morgenstern_at_[hidden]>:

> I found a way to get a type_name type at compile type, i.e. a template
> which has a sequence of chars representing the type. This could be added to
> boost.type_index and would allow constexpr sorting of types by names etc.
> E.g. making boost::variant<int, double> and boost::variant<double, int> the
> same, by ordering the arguments alphabetically. Has lot of compiler
> overhead though.
>

I've tried to use __PRETTY_FUNCTION__ directly a year or two ago. Some
compilers allowed that, some not.

Could you try to compile that code on Clang? If that works, try to mark
detail::ctti<T>::n() with constexpr and use in your code:

    template<std::size_t Index>
    constexpr static char step()
    {
        return detail::ctti<T>::n()[Index];
    }

If that works, then it would be a really great addition to type_index!

That might also be a workaround for the REGISTER_TYPE thing in you magic
> get, though I have to admit: I don't really get how this approach works, so
> I don't know.
>

That won't help. I need a way to make conversion of T type to some
non-templated class and back:
T -> int -> T

TypeIndex allows only the first part of that: T -> type_index, but does not
allow type_index -> T

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk