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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Reference

AUTO, AUTO_TPL
COMPLIANT
INCREMENT_REGISTRATION_GROUP
INTEGRAL
LIMIT_FUNCTION_ARITY
MESSAGES
LIMIT_SIZE
REGISTER_TYPE
REGISTER_TEMPLATE
TEMPLATE
TYPEOF, TYPEOF_TPL
TYPEOF_NESTED_TYPEDEF, TYPEOF_NESTED_TYPEDEF_TPL

AUTO, AUTO_TPL

The BOOST_AUTO macro emulates the proposed auto keyword in C++.

Usage
BOOST_AUTO(var,expr)
BOOST_AUTO_TPL(var,expr)

Arguments

var

a variable to be initialized with the expression

expr

a valid c++ expression

Remarks

If you want to use auto in a template-context, use BOOST_AUTO_TPL(expr), which takes care of the typename keyword inside the auto expression.

Sample Code
int main()
{
    length::meter a(5);
    force::newton b(6);
    BOOST_AUTO(c, a * b);
}

COMPLIANT

The BOOST_TYPEOF_COMPLIANT macro can be used to force the emulation mode. Define it if your compiler by default uses another mode, such as native typeof or Microsoft-specific trick, but you want to use the emulation mode, for example for portability reasons.

INCREMENT_REGISTRATION_GROUP

The BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP macro ensures that type registrations in different header files receive unique identifiers.

Usage
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
Remarks

specified once in every cpp/hpp file where any registration is performed, before any registration.

Sample Code
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()

class X;
BOOST_TYPEOF_REGISTER_TYPE(X)

INTEGRAL

The BOOST_TYPEOF_INTEGRAL macro is used when registering an integral template parameter using BOOST_TYPEOF_REGISTER_TEMPLATE.

Useful for enums and dependent integral template parameters.

Usage
BOOST_TYPEOF_INTEGRAL(x)

Arguments

x

a fully qualified integral type or enum

Remarks

A short syntax has been implemented for the built in types (int, bool, long, unsigned long, etc.) Other non-type template parameters (e.g. pointer to member) are not supported.

Sample Code
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()

namespace foo
{
    enum color {red, green, blue};

    template<color C0,typename T1>
    class class_with_enum {};

    template<typename T0,T0 I1>
    class class_with_dependent_non_type {};
}

BOOST_TYPEOF_REGISTER_TEMPLATE(foo::class_with_enum,
    (BOOST_TYPEOF_INTEGRAL(foo::color))
    (typename)
    )

BOOST_TYPEOF_REGISTER_TEMPLATE(foo::class_with_dependent_non_type,
    (typename)
    (BOOST_TYPEOF_INTEGRAL(P0))
    )

LIMIT_FUNCTION_ARITY

The BOOST_TYPEOF_LIMIT_FUNCTION_ARITY macro defines how many parameters are supported for functios, and applies to functions, function pointers, function references, and member function pointers. The default value is 10. Redefine if you want the Typeof Library to handle functions with more parameters.

MESSAGES

Define BOOST_TYPEOF_MESSAGE before including boost/typeof/typeof.hpp to include messages "using typeof emulation" and "using native typeof". By default, these messages will not be displayed.

LIMIT_SIZE

The BOOST_TYPEOF_LIMIT_SIZE macro defines the size of the compile-time sequence used to encode a type. The default value is 50. Increase it if you want the Typeof Library to handle very complex types, although this possibility is limited by the maximum number of template parameters supported by your compiler. On the other hand, if you work only with very simple types, decreasing this number may help to boost compile-time performance.

REGISTER_TYPE

The BOOST_TYPEOF_REGISTER_TYPE macro informs the Typeof Library about the existence of a type

Usage
BOOST_TYPEOF_REGISTER_TYPE(x)

Arguments

x

a fully qualified type

Remarks

Must be used in the global namespace

Sample Code
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()

namespace foo
{
    class bar {};
    enum color {red, green, blue};
}

BOOST_TYPEOF_REGISTER_TYPE(foo::bar)
BOOST_TYPEOF_REGISTER_TYPE(foo::color)

REGISTER_TEMPLATE

The BOOST_TYPEOF_REGISTER_TEMPLATE macro informs the Typeof Library about the existence of a template and describes its parameters

Usage
BOOST_TYPEOF_REGISTER_TEMPLATE(x, n)
BOOST_TYPEOF_REGISTER_TEMPLATE(x, seq)

Arguments

x

a fully qualified template

n

the number of template arguments. Only valid if all template arguments are typenames

seq

a sequence of template arguments. Must be used when integral or template template parameters are present

Remarks

Must be used in the global namespace.

The library allows registration of templates with type, integral, and template template parameters:

  • A type template parameter is described by the (class) or (typename) sequence element
  • A template parameter of a well-known integral type can be described by simply supplying its type, like (unsigned int). The following well-known integral types are supported:
    • [signed/unsigned] char
    • [unsigned] short
    • [unsigned] int
    • [unsigned] long
    • unsigned
    • bool
    • size_t
  • Enums and typedefs of integral types, need to be described explicitly with the BOOST_TYPEOF_INTEGRAL macro, like (BOOST_TYPEOF_INTEGRAL(MyEnum))
  • Template template parameters are described with the BOOST_TYPEOF_TEMPLATE macro, like: (BOOST_TYPEOF_TEMPLATE((class)(unsigned int))). In case of all type parameters this can be shortened to something like (BOOST_TYPEOF_TEMPLATE(2)). The nested template template parameters are not supported.
Sample Code
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()

namespace foo
{
    template<typename T0, typename T1>
    class simple_template {};

    template<typename T0, int I1>
    class class_with_integral_constant {};
}

BOOST_TYPEOF_REGISTER_TEMPLATE(foo::simple_template, 2)
BOOST_TYPEOF_REGISTER_TEMPLATE(foo::class_with_integral_constant, (typename)(int))

TEMPLATE

The BOOST_TYPEOF_TEMPLATE macro is used when registering template template parameters using BOOST_TYPEOF_REGISTER_TEMPLATE.

Usage
BOOST_TYPEOF_TEMPLATE(n)
BOOST_TYPEOF_TEMPLATE(seq)

Arguments

n

the number of template arguments. Only valid if all template arguments are typenames

seq

a sequence of template arguments. Must be used when there are integral constants in the nested template

Remarks

Can not be used to register nested template template parameters.

Sample Code
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()

namespace foo
{
    enum color {red, green, blue};

    template<color C0, template<typename> class T1>
    class nested_template_class {};

    template<template<typename, unsigned char> class T1>
    class nested_with_integral {};
}

BOOST_TYPEOF_REGISTER_TEMPLATE(foo::nested_template_class,
    (foo::color)
    (BOOST_TYPEOF_TEMPLATE(1))
    )

BOOST_TYPEOF_REGISTER_TEMPLATE(foo::nested_with_integral,
    (BOOST_TYPEOF_TEMPLATE((typename)(unsigned char)))
    )

TYPEOF, TYPEOF_TPL

The BOOST_TYPEOF macro calculates the type of an expression, but removes the top-level qualifiers, const&

Usage
BOOST_TYPEOF(expr)
BOOST_TYPEOF_TPL(expr)

Arguments

expr

a valid c++ expression that can be bound to const T&

Remarks

If you want to use typeof in a template-context, use BOOST_TYPEOF_TPL(expr), which takes care of typename inside the typeof expression.

Sample Code
template<typename A, typename B>
struct result_of_conditional
{
    typedef BOOST_TYPEOF_TPL(true?A():B()) type;
};

template<typename A, typename B>
result_of_conditional<A, B>::type min(const A& a,const B& b)
{
    return a < b ? a : b;
}

TYPEOF_NESTED_TYPEDEF, TYPEOF_NESTED_TYPEDEF_TPL

The TYPEOF_NESTED_TYPEDEF macro works in much the same way as the 'TYPEOF' macro does, but workarounds several compiler deficiencies.

Usage
BOOST_TYPEOF_NESTED_TYPEDEF(name,expr)
BOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr)

Arguments

name

a valid identifier to nest the typeof operation inside

expr

a valid c++ expression that can be bound to const T&

Remarks

'typeof_nested_typedef' nests the 'typeof' operation inside a struct. By doing this, the 'typeof' operation can be split into two steps, deconfusing several compilers (notably VC7.1 and VC8.0) on the way. This also removes the limitation imposed by BOOST_TYPEOF_LIMIT_SIZE and allows you to use 'typeof' on much larger expressions.

If you want to use typeof_nested_typedef in a template-context, use BOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr), which takes care of typename inside the typeof expression.

'typeof_nested_typedef' can not be used at function/block scope.

Sample Code
template<typename A, typename B>
struct result_of_conditional
{
    BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested,true?A():B())
    typedef typename nested::type type;
};

template<typename A, typename B>
result_of_conditional<A, B>::type min(const A& a,const B& b)
{
    return a < b ? a : b;
}

PrevUpHomeNext