Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Next

Chapter 1. The Type Traits Introspection Library

Edward Diener

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Introduction
Header Files
Why the TTI Library ?
Terminology
General Functionality
Macro metafunction name generation considerations
Macro Metafunctions
Introspecting an inner type
Introspecting a specific user-defined type
Introspecting an inner class template
Using the BOOST_TTI_HAS_TEMPLATE macro
Using the has_template_(xxx) metafunction
Introspecting function templates technique
Introspecting member data
Introspecting member function
Introspecting member function template
Introspecting static member data
Introspecting static member function
Introspecting static member function template
Introspecting data
Introspecting function
Introspecting function template
Nested Types
Nested Types and Function Signatures
Enclosing Type
An example using the macro metafunctions
Reference
Header <boost/tti/gen/has_class_gen.hpp>
Header <boost/tti/gen/has_data_gen.hpp>
Header <boost/tti/gen/has_enum_gen.hpp>
Header <boost/tti/gen/has_function_gen.hpp>
Header <boost/tti/gen/has_function_template_gen.hpp>
Header <boost/tti/gen/has_member_data_gen.hpp>
Header <boost/tti/gen/has_member_function_gen.hpp>
Header <boost/tti/gen/has_member_function_template_gen.hpp>
Header <boost/tti/gen/has_static_member_data_gen.hpp>
Header <boost/tti/gen/has_static_member_function_gen.hpp>
Header <boost/tti/gen/has_static_member_function_template_gen.hpp>
Header <boost/tti/gen/has_template_gen.hpp>
Header <boost/tti/gen/has_type_gen.hpp>
Header <boost/tti/gen/has_union_gen.hpp>
Header <boost/tti/gen/member_type_gen.hpp>
Header <boost/tti/gen/namespace_gen.hpp>
Header <boost/tti/has_class.hpp>
Header <boost/tti/has_data.hpp>
Header <boost/tti/has_enum.hpp>
Header <boost/tti/has_function.hpp>
Header <boost/tti/has_function_template.hpp>
Header <boost/tti/has_member_data.hpp>
Header <boost/tti/has_member_function.hpp>
Header <boost/tti/has_member_function_template.hpp>
Header <boost/tti/has_static_member_data.hpp>
Header <boost/tti/has_static_member_function.hpp>
Header <boost/tti/has_static_member_function_template.hpp>
Header <boost/tti/has_template.hpp>
Header <boost/tti/has_type.hpp>
Header <boost/tti/has_union.hpp>
Header <boost/tti/member_type.hpp>
Testing TTI
History
ToDo
Acknowledgments
Index

Welcome to the Boost Type Traits Introspection library, abbreviated TTI.

TTI is a library which provides the ability to introspect by name the elements of a type at compile time.

TTI works through macros generating metafunctions. Metafunctions are class templates of a particular syntax, having a nested 'type' member. So wherever in C++ class templates can occur, TTI macros can be used. The metafunctions generated by TTI are no different from any other metafunction as defined by the Boost MPL library.

The metafunctions generated by TTI are used to introspect elements of a type at compile time, always passing at minimum to each metafunction the enclosing type being introspected.

The name of the library has been chosen because the library offers compile time functionality on a type, similar to the Boost Type Traits library, and because the functionality the library offers is the ability to introspect a type about the existence of a specific element within that type.

I use the word "introspect" in a very broad sense here. Normally computer language introspection means initially asking for information to be returned by name, which can then further be used to introspect for more specific information. In the TTI library one must always know and supply the name, and use the functionality provided for the correct type of inner element to find out if that particular named entity exists.

You may prefer the term "query" instead of "introspection" to denote what this library does, but I use terminology based on the word "introspect" throughout this documentation.

The functionality of the library may be summed up as:

  • Provide the means to introspect a type at compile time using a set of macros. Each macro takes the name of the type's element and generates a metafunction which can be subsequently invoked to determine whether or not the element exists within the type. These generated metafunctions will be called "macro metafunctions" in the documentation. The type to be introspected can be a class, struct, or union.
  • Provide the means to create a typedef for a type which may not exist. If the type does not exist an empty marker type is returned as the typedef type. This typedef type can be used as a type in the metafunctions of the library without producing compile-time errors.

The library is dependent on Boost PP, Boost MPL, Boost Type Traits, and Boost Function Types.

The library is also dependent on the variadic macro support of the Boost PP library if the variadic macros in the library are used.

The library is a header only library.

Since the dependencies of the library are all header only libraries, there is no need to build a library in order to use the TTI library.

There is a single header file, boost/tti/tti.hpp, which includes all the header files in the library.

There are also separate specific header files for each of the elements to be introspected by the library. This allows for finer-grained inclusion of the nested elements to be introspected. These header files are:

Table 1.1. TTI Header Files

Introspected Element

Specific Header File

Type

has_type.hpp

Class/Struct

has_class.hpp

Enumeration

has_enum.hpp

Union

has_union.hpp

Class Template

has_template.hpp

Member data

has_member_data.hpp

Member function

has_member_function.hpp

Member function template

has_member_function_template.hpp

Static member data

has_static_member_data.hpp

Static member function

has_static_member_function.hpp

Static member function template

has_static_member_function_template.hpp

Data

has_data.hpp

Function

has_function.hpp

Function template

has_function_template.hpp

Member Type Creation

member_type.hpp



Next