Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2000-11-21 13:03:57


On Mon, 20 Nov 2000, Matthew Austern wrote:
> - I keep hoping that there might be a way to eliminate the
> use of macros. Token pasting, in particular, is distasteful.

Here's my first stab at a non-macro approach:

First, for the function requires we can just use a function
template like this:

template <class Concept>
void function_requires()
{
  void (Concept::*x)() = BOOST_FPTR Concept::constraints;
  ignore_unused_variable_warning(x);
}

And then use explicit template arguments to invoke it:

boost::function_requires< DefaultConstructibleConcept<foo> >();

Second, for class requires we can create a class template
like this:

template <class Concept>
struct class_requires
{
  typedef void (Concept::* function_pointer)();

  template <function_pointer Fptr>
  struct dummy_struct { };

  typedef dummy_struct< BOOST_FPTR Concept::constraints > check;
};

and then invoke it like this:

class class_requires_test
{
  typedef class_requires< EqualityComparableConcept<int> >::check req1;

  // ...
};

The "::check" at the end was required to enforce compilation of
the checking code under KAI C++.

I've tested on g++, KAI C++, and VC++ so far. The class_requires
doesn't work with VC++ for the same reason the old macro did
not: no support of function pointer template parameters.

Cheers,

Jeremy

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate email: jsiek_at_[hidden]
 Univ. of Notre Dame work phone: (219) 631-3906
----------------------------------------------------------------------


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