[TTI] macro to "box" types for subsequent traits extraction?
Hi everyone, this is my first post to this mailinglist, so I hope I follow the proper conventions around here (yes, I did read the Discussion Policy). I have a small feature request for the Type Traits Introspection library: a macro BOOST_TTI_BOX_TYPE(U) that defines a class template box_type<T> with a nested typedef named "type" that equals T::U. Rationale: because box_type<T> is a metafunction that can be supplied to mpl::eval_if, this facilitates user-defined traits that extract a nested type U, but can fall back to a (user-defined) default type. This mimics the C++11 allocator_traits that also provide defaults for allocators that lack certain nested typedefs or other properties. Small self-contained example: http://coliru.stacked-crooked.com/a/76b9abf4aaf00350 One could probably also define similar "boxing" macros to go along with the has_template and other introspection tools in TTI. Would this be considered a useful feature? Rein
On 5/5/2014 11:03 AM, Rein Halbersma wrote:
Hi everyone, this is my first post to this mailinglist, so I hope I follow the proper conventions around here (yes, I did read the Discussion Policy).
I have a small feature request for the Type Traits Introspection library: a macro BOOST_TTI_BOX_TYPE(U) that defines a class template box_type<T> with a nested typedef named "type" that equals T::U.
Rationale: because box_type<T> is a metafunction that can be supplied to mpl::eval_if, this facilitates user-defined traits that extract a nested type U, but can fall back to a (user-defined) default type. This mimics the C++11 allocator_traits that also provide defaults for allocators that lack certain nested typedefs or other properties.
Small self-contained example: http://coliru.stacked-crooked.com/a/76b9abf4aaf00350
One could probably also define similar "boxing" macros to go along with the has_template and other introspection tools in TTI.
Would this be considered a useful feature?
Could you look at the documentation for BOOST_TTI_MEMBER_TYPE in the section called "Nested Types" of the TTI documentation ? I think you can easily adapt this to the purposes of your example.
On Wed, May 7, 2014 at 2:03 AM, Edward Diener
Could you look at the documentation for BOOST_TTI_MEMBER_TYPE in the section called "Nested Types" of the TTI documentation ? I think you can easily adapt this to the purposes of your example.
Thanks! The closely related BOOST_TTI_TRAIT_MEMBER_TYPE does exactly what I
need:
#include
On May 5, 2014 11:03:01 AM EDT, Rein Halbersma
I have a small feature request for the Type Traits Introspection library: a macro BOOST_TTI_BOX_TYPE(U) that defines a class template box_type<T> with a nested typedef named "type" that equals T::U.
Where does the macro get T?
Small self-contained example: http://coliru.stacked-crooked.com/a/76b9abf4aaf00350
Posting the code facilitates later searching and prevents problems on finding out later (should the linked site disappear or the linked code be deleted on the future). It also permits quoting portions in replies. ___ Rob (Sent from my portable computation engine)
On Wed, May 7, 2014 at 10:55 AM, Rob Stewart
On May 5, 2014 11:03:01 AM EDT, Rein Halbersma
wrote: I have a small feature request for the Type Traits Introspection library: a macro BOOST_TTI_BOX_TYPE(U) that defines a class template box_type<T> with a nested typedef named "type" that equals T::U.
Where does the macro get T?
T would be the template parameter of the class template generated by the macro #define BOOST_TTI_BOX_TYPE(U) \ template<class T> \ struct box_type_ ## U \ { \ using type = typename T::U; \ };
Small self-contained example: http://coliru.stacked-crooked.com/a/76b9abf4aaf00350
Posting the code facilitates later searching and prevents problems on finding out later (should the linked site disappear or the linked code be deleted on the future). It also permits quoting portions in replies.
OK, will do next time. Rein
participants (3)
-
Edward Diener
-
Rein Halbersma
-
Rob Stewart