Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-06-07 16:58:05


Here's another variation that I had considered previously, and am now
considering again. The only problem with this one is that if the user
forgets the "::type" then the check doesn't do anything.

#include <boost/concept_check.hpp>

namespace boost {
  template <class Concept>
  struct class_requires
  {
    typedef void (Concept::*function_type)();
    template <function_type f>
    struct invoke { };
    typedef invoke<&Concept::constraints> type;
  };
} // namespace boost

namespace foo {
  template <class T>
  struct Vector
  {
    typedef boost::class_requires< boost::SGIAssignableConcept<T> >::type req;
  };
}// namespace foo

struct bar {
  bar(int) { }
private:
  bar(const bar&) { }
};

int main()
{
  foo::Vector<bar> v;
  return 0;
}

On Thu, 7 Jun 2001, David Abrahams wrote:

> All I can say is, "beware the multiple inheritance empty base class bloat"!
>
> ;-)
>
> Avoiding macros is good, though.
> -Dave
>
> ----- Original Message -----
> From: "Jeremy Siek" <jsiek_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Thursday, June 07, 2001 5:23 PM
> Subject: [boost] concept checking: BOOST_CLASS_REQUIRES
>
>
> > Hi All,
> >
> > BOOST_CLASS_REQUIRES is a bit broken, but instead of fixing it I'm
> > thinking of moving to the non-macro approach suggested by Bjarne:
> >
> > http://www.research.att.com/~bs/bs_faq2.html#constraints
> >
> > Here's how I envision the concept check working for a class:
> >
> >
> > #include <boost/concept_check.hpp>
> >
> > namespace boost {
> > template <class Concept>
> > struct class_requires {
> > class_requires() { function_requires<Concept>(); }
> > };
> > } // namespace boost
> >
> >
> > namespace foo {
> > template <class T>
> > struct Vector
> > : public boost::class_requires< boost::SGIAssignableConcept<T> >
> > {
> > };
> > }// namespace foo
> >
> > struct bar {
> > bar(int) { }
> > private:
> > bar(const bar&) { }
> > };
> >
> > int main()
> > {
> > foo::Vector<bar> v;
> > return 0;
> > }
> >
> >
> >
> > ----------------------------------------------------------------------
> > Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
> > Ph.D. Candidate, IU B'ton email: jsiek_at_[hidden]
> > Summer Manager, AT&T Research phone: (973) 360-8185
> > ----------------------------------------------------------------------
> >
> >
> >
> > To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
> >
> >
> > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
> >
> >
>
>
> To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate, IU B'ton email: jsiek_at_[hidden]
 Summer Manager, AT&T Research phone: (973) 360-8185
----------------------------------------------------------------------


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