Front Page / Metafunctions / Miscellaneous / sizeof_

sizeof_

Synopsis

template<
      typename X
    >
struct sizeof_
{
    typedef unspecified type;
};

Description

Returns the result of a sizeof(X) expression wrapped into an Integral Constant of the corresponding type, std::size_t.

Header

#include <boost/mpl/sizeof.hpp>

Model of

Metafunction

Parameters

Parameter Requirement Description
X Any type A type to compute the sizeof for.

Expression semantics

For an arbitrary type x:

typedef sizeof_<x>::type n;
Return type:

Integral Constant.

Precondition:

x is a complete type.

Semantics:

Equivalent to

typedef size_t< sizeof(x) > n;

Complexity

Constant time.

Example

struct udt { char a[100]; };

BOOST_MPL_ASSERT_RELATION( sizeof_<char>::value, ==, sizeof(char) );
BOOST_MPL_ASSERT_RELATION( sizeof_<int>::value, ==, sizeof(int) );
BOOST_MPL_ASSERT_RELATION( sizeof_<double>::value, ==, sizeof(double) );
BOOST_MPL_ASSERT_RELATION( sizeof_<udt>::value, ==, sizeof(my) );

See also

Metafunctions, Integral Constant, size_t