Boost logo

Boost :

Subject: Re: [boost] [TTI] macro to "box" types for subsequent traits extraction?
From: Rein Halbersma (rhalbersma_at_[hidden])
Date: 2014-05-07 07:55:02


On Wed, May 7, 2014 at 2:03 AM, Edward Diener <eldiener_at_[hidden]>wrote:

> 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 <boost/tti/member_type.hpp>
#include <type_traits>

// define class template X_trait with nested member type X
BOOST_TTI_TRAIT_MEMBER_TYPE(X_trait, X)

// convenient type extraction which defaults to int
template<class T>
using X_trait_t = typename X_trait<T, int>::type;

struct T1 { /* X defaults to int */ };
struct T2 { using X = char; };

int main()
{
    static_assert(std::is_same<X_trait_t<T1>, int >::value, "");
    static_assert(std::is_same<X_trait_t<T2>, char>::value, "");
}


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