3 ms·
> Thats all! Simple, isn’t it? Here’s std::decay in the Turbo way: template< class T > struct decay { using U = tml::eval<std::remove_reference<T>>;
by kazinator 12y ago
> Thats all! Simple, isn’t it? Here’s std::decay in the Turbo way:
template< class T >
struct decay {
using U = tml::eval<std::remove_reference<T>>;
using type = tml::eval<
tml::conditional<
std::is_array<U>,
tml::eval<std::remove_extent<U>>*,
tml::conditional<
std::is_function<U>,
std::add_pointer<U>,
std::remove_cv<U>
>
>
>;
};
> I found it much more readable. What do you think?
I think:
1. Programming in XML notation is starting to look good, suddenly.
2.
(def-compile-time-gizmo decay (x)
(let ((u (remove-reference x)))
(cond
((is-array u) (remove-extent u))
((is-function u) (add-pointer u))
(t (remove-cv u)))))
3. Why isn't tml::conditional just called tml::if, if it (evidently) only takes three arguments: expr, then, else?
- pjtr 12y ago3: Probably because if is a keyword and can't be used. (And it's based on ''std::conditional'' standardized in C++ 11, but that's begging the question.)
- Manu343726 12y agoExactly. if is a C++ keyword. I selected tml::conditional following the Standard std::conditional. The boost::mpl library uses mpl::if_, for example.
- Manu343726 12y ago"Programming in XML notation is starting to look good, suddenly" I hate the typename ::type pattern. tml::eval helps a lot, but still involves a lot of nested template "calls". To deal with this, I'm working on a continuation system for C++ templates: https://github.com/Manu343726/Flux https://github.com/Manu343726/Flux