Opened 21 years ago

Closed 17 years ago

#933 closed Bugs (Fixed)

Can't use BOOST_CLASS_REQUIRES macro

Reported by: ksvanhorn Owned by: jsiek
Milestone: Component: concept_check
Version: None Severity:
Keywords: Cc:

Description

The BOOST_CLASS_REQUIRES macro does not work correctly
when used outside of the boost namespace.  For example,
if I write

template <typename RandIter>
class foo {
  BOOST_CLASS_REQUIRES(RandIter,
boost::RandomAccessIteratorConcept);
  ...
};

I get a syntax error at the macro, because the
implementation of the macro assumes that the second
argument is an unqualified name.

A possible, but not terribly satisfactory, workaround
is to use a typedef; I would suggest that if you can't
find a good way to fix this problem, you should
document both the problem and its workaround.

Change History (4)

comment:1 by ksvanhorn, 21 years ago

Logged In: YES 
user_id=239593

I just tried out the workaround, and it doesn't work --
the second argument needs to be a template, and C++ doesn't
have template typedefs.  So I know of no workaround at all
for this problem.

comment:2 by jsiek, 21 years ago

Logged In: YES 
user_id=32836

One option is to added a parameter to the macro for the
namespace.
I'm not all that crazy about that solution. Perhaps there's
a better way...

comment:3 by jsiek, 21 years ago

Logged In: YES 
user_id=32836

Here's an alternative to BOOST_CLASS_REQUIRES from Bjarne:

http://www.research.att.com/~bs/bs_faq2.html#constraints

// Here's how I'd adapt it into the boost concept checking
library

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

comment:4 by jsiek, 17 years ago

Status: assignedclosed
Note: See TracTickets for help on using tickets.