| Home | Libraries | People | FAQ | More

## Macro BOOST_TTI_HAS_CLASS

BOOST_TTI_HAS_CLASS — A macro which expands to a metafunction which tests whether an inner class/struct with a particular name exists.

## Synopsis

    // In header: <boost/tti/has_class.hpp>

    BOOST_TTI_HAS_CLASS(name)

## Description

BOOST_TTI_HAS_CLASS is a macro which expands to a metafunction. The metafunction tests whether an inner class/struct with a particular name exists and, optionally, whether an MPL lambda expression invoked with the inner class/struct is true or not. The macro takes the form of BOOST_TTI_HAS_CLASS(name) where

name = the name of the inner class/struct.

BOOST_TTI_HAS_CLASS generates a metafunction called "has_class_'name'" where 'name' is the macro parameter.

    template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_U>
    struct has_class_'name'
      {
      static const value = unspecified;
      typedef mpl::bool_<true-or-false> type;
      };

    The metafunction types and return:

      BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
                       The enclosing type can be a class, struct, or union.

      BOOST_TTI_TP_U = (optional) An optional template parameter, defaulting to a marker type.
                         If specified it is an MPL lambda expression which is invoked
                         with the inner class/struct found and must return a constant boolean
                         value.

      returns = 'value' depends on whether or not the optional BOOST_TTI_TP_U is specified.

                If BOOST_TTI_TP_U is not specified, then 'value' is true if the 'name' class/struct
                exists within the enclosing type BOOST_TTI_TP_T; otherwise 'value' is false.

                If BOOST_TTI_TP_U is specified, then 'value' is true if the 'name' class/struct exists
                within the enclosing type BOOST_TTI_TP_T and the MPL lambda expression as specified
                by BOOST_TTI_TP_U, invoked by passing the actual inner class/struct of 'name', returns
                a 'value' of true; otherwise 'value' is false.

                The action taken with BOOST_TTI_TP_U occurs only when the 'name' class/struct exists
                within the enclosing type BOOST_TTI_TP_T.

Example usage:

    BOOST_TTI_HAS_CLASS(MyType) generates the metafunction "has_class_MyType" in the current scope
    to look for an inner class/struct called MyType.

    has_class_MyType<EnclosingType>::value is true if MyType is an inner class/struct of EnclosingType, otherwise false.

    has_class_MyType<EnclosingType,ALambdaExpression>::value is true if MyType is an inner class/struct of EnclosingType
      and invoking ALambdaExpression with the inner class/struct returns a value of true, otherwise false.

    A popular use of the optional MPL lambda expression is to check whether the class/struct found is the same
    as another type, when the class/struct found is a typedef. In that case our example would be:

    has_class_MyType<EnclosingType,boost::is_same<_,SomeOtherType> >::value is true if MyType is an inner class/struct
      of EnclosingType and is the same type as SomeOtherType.