Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-12-05 10:18:16


----- Original Message -----
From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> Could you post a complete example?.
> If I test the above with a "detail::arg_tuple_size<T>::value" equal to
> "sizeof(T)" it compiles fine.

Voila. I can't get the no-partial-specialization branch of the code to work
with Borland either:

// Copyright David Abrahams 2001. Permission to copy, use,
// modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
#include <boost/static_assert.hpp>
#include <cstddef>

// Computes (at compile-time) the number of elements that a Python
// argument tuple must have in order to be passed to a wrapped C++
// (member) function of the given type.
template <class F> struct arg_tuple_size;

# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)

template <class R>
struct arg_tuple_size<R (*)()>
{
    BOOST_STATIC_CONSTANT(std::size_t, value = 0);
};

template <class R, class A0>
struct arg_tuple_size<R (A0::*)()>
{
    BOOST_STATIC_CONSTANT(std::size_t, value = 1);
};

# else

// We will use the "sizeof() trick" to work around the lack of
// partial specialization in MSVC6. See
// http://opensource.adobe.com or
// http://groups.yahoo.com/group/boost/message/5441 for
// more examples

// This little package is used to transmit the number of arguments
// from the helper functions below to the sizeof() expression below.
// Because we can never have an array of fewer than 1 element, we
// add 1 to n and then subtract 1 from the result of sizeof() below.
template <int n>
struct char_array
{
    char elements[n+1];
};

// The following helper functions are never actually called, since
// they are only used within a sizeof() expression, but the type of
// their return value is used to discriminate between various free
// and member function pointers at compile-time.

template <class R>
char_array<0> arg_tuple_size_helper(R (*)());

template <class R, class A0>
char_array<1> arg_tuple_size_helper(R (A0::*)());

template <class F>
struct arg_tuple_size
{
    // The sizeof() magic happens here
    BOOST_STATIC_CONSTANT(std::size_t, value
      = sizeof(arg_tuple_size_helper(F(0)).elements) - 1);
};

# endif

struct X {};

int main()
{
    BOOST_STATIC_ASSERT(arg_tuple_size<void (X::*)()>::value == 1);
    return 0;
}


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