Boost logo

Boost Users :

From: Igor Bashkirov (igor_bashkirov_at_[hidden])
Date: 2002-08-20 22:14:00


Hi Jeremy,

--- Jeremy Siek <jsiek_at_[hidden]> wrote:
> Hi Igor,
>
> What about concepts defined within a doubly nested
> namespace? Will that
> also work?
>

You're right. There is a problem in my solution caused
by using 'ns' macro parameter in constructing names.
So, we could sacrifice the uniqueness of names to
usability.
The fixed solution looks like following:

[code

#define BOOST_CLASS_REQUIRES(type_var, ns, concept) \
  typedef void (ns::concept <type_var>::*
func##type_var##concept)(); \
  template <func##type_var##concept _Tp1> \
  struct concept_checking_##type_var##concept { }; \
  typedef concept_checking_##type_var##concept< \
    BOOST_FPTR ns::concept <type_var>::constraints> \
    concept_checking_typedef_##type_var##concept

end code]

Actually, it was the first version I tried.
Now it will work for nested namespaces:

[code

namespace ns1
{
  namespace ns2
  {
    template <class TT>
    class DummyConcept
    {
      void constraints() { /* dummy */}
    };
  }
}

template <class T>
class X
{
  BOOST_CLASS_REQUIRES(T, ns1::ns2, DummyConcept);
};

int main(int, char**)
{
  X<int> x1;
  return 0;
}

end code]

> Have you tested the code below with VC++?
>

Yes, I tested it with VC++, SP5.

Actually, VC++ is very freakish in concern to
templates.
Let me give an example that expose one of the strange
behaviours of VC++ that couldn't be understood from
the point of view of common sense:

[code

template <class TT>
class A
{
public:
  void foo() {}
};

template <class T, class V>
class X
{
  typedef void (A<T>::*fp)();
  template <fp _Tp1> struct ss { };
  typedef ss<&A<T>::foo> tt;
};

int main(int, char**)
{
  X<int, float> x1;
  return 0;
}

end code]

The above example will compile, but the following
won't:

[code

template <class TT>
class A
{
public:
  void foo() {}
};

template <class T, class V>
class X
{
  typedef void (A<V>::*fp)();
  template <fp _Tp1> struct ss { };
  typedef ss<&A<V>::foo> tt;
};

int main(int, char**)
{
  X<int, float> x1;
  return 0;
}

end code]

And I'm not surprised, because I have compiled more
than 20 deficiencies of VC++ compiler mostly concerned
C++ templates support.

Best regards,
     Igor Bashkirov.

> On Tue, 20 Aug 2002, igor_bashkirov wrote:
> igor_b>
> igor_b> [code
> igor_b>
> igor_b> #define BOOST_CLASS_REQUIRES(type_var, ns,
> concept) \
> igor_b> typedef void (ns::concept <type_var>::*
> func##type_var##ns##concept)
> igor_b> (); \
> igor_b> template <func##type_var##ns##concept
> _Tp1> \
> igor_b> struct
> concept_checking_##type_var##ns##concept { }; \
> igor_b> typedef
> concept_checking_##type_var##ns##concept< \
> igor_b> BOOST_FPTR ns::concept
> <type_var>::constraints> \
> igor_b>
> concept_checking_typedef_##type_var##ns##concept;
> igor_b>
> igor_b> end code]
>
>
>
----------------------------------------------------------------------
> Jeremy Siek
> http://php.indiana.edu/~jsiek/
> Ph.D. Student, Indiana Univ. B'ton email:
> jsiek_at_[hidden]
> C++ Booster (http://www.boost.org) office phone:
> (812) 855-3608
>
----------------------------------------------------------------------
>
>
>

__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net