Boost logo

Boost Users :

From: chun ping wang (cablepuff_at_[hidden])
Date: 2007-09-26 18:47:00


what i want to do is if type "T" happens to be a integeral type *or* a class
type that inherits from boost::operators than let the function compile
otherwise a compile time error appears. Basically T is any integeral type or
any class type that derives from boost::operators.

On 9/26/07, David Abrahams <dave_at_[hidden]> wrote:
>
>
> on Wed Sep 26 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
>
> > template <typename T>
> > bool boost::pseudoprime(const T& n, const T& k)
> > {
> > typedef boost::operators<T> operatorT;
> > BOOST_STATIC_ASSERT(is_integral<T>::value); // static assert 1.
> > BOOST_STATIC_ASSERT((is_base_of<operatorT, T>::value)); // static
> assert 2.
> > BOOST_ASSERT (n > T(2) && n % T(2) != 0);
> > return modular_expo(k, n-1, n) != T(1) % n ? true : false;
> > }
> >
> > now in vistual studio 2005 sp1 and visual studio 2008 beta the part
> "is_base_of<operatorT,
> > T>::value" does not work if T happens to be an int or long due to "error
> C2803: 'operator --'
> > must have at least one formal parameter of class type". I want to use
> enable_if to enable the
> > STATIC_ASSERT only if T is NOT an arithmetic type for static assert 2.
>
> enable_if can't "enable static asserts" in any sense that I
> understand. What are you really trying to do? Try to describe it
> without mentioning enable_if or STATIC_ASSERT. Just talk about the
> behavior you want.
>
> --
> Dave Abrahams
> Boost Consulting
> http://www.boost-consulting.com
>
> The Astoria Seminar ==> http://www.astoriaseminar.com
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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