|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2007-10-01 17:59:24
on Mon Oct 01 2007, "chun ping wang" <cablepuff-AT-gmail.com> wrote:
> hmm that is what i want for now... (i might change it later). I want to know to keept it in back
> of my head. Thanks.
>
> On 10/1/07, David Abrahams < dave_at_[hidden]> wrote:
>
> on Wed Sep 26 2007, "chun ping wang" < cablepuff-AT-gmail.com> wrote:
>
> > 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.
>
> I could tell you how, but it seems ill-advised. I really doubt you
> want to fail compilation if someone passes you a class type that acts
> just like int, but that isn't written using boost::operators. Are you
> sure that's what you want?
// untested
template <class T, class U>
char (& is_op_test(operators<T,U> const&) )[2]
template <class T>
char is_op_test(T const&);
template<class T>
T const& make();
template <class T>
struct is_operators
: mpl::bool_<(sizeof(is_op_test(make<T>())) == 2)>
{};
template <class T>
typename enable_if<mpl::or_<boost::is_integral<T>, is_operators<T> >, return_type>::type
f(T x)
{
...
}
-- Dave Abrahams Boost Consulting http://www.boost-consulting.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