Boost logo

Boost :

Subject: Re: [boost] arithmetic meta functions and traits
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-12-06 04:33:57

On Sun, Dec 6, 2009 at 3:19 AM, joel falcou <joel.falcou_at_[hidden]> wrote:

> Zachary Turner wrote:
>> The sizeof trick I'm aware of is comparing the size against an "unlikely"
>> size N, something very large such as 43280 such that you're unlikely to
>> come
>> across two types P and Q such that sizeof(P()+Q()) == N. Is there any
>> reason this method is preferable to the method I used above though, where
>> it
>> can provably never result in a false negative?
> You get it wrong, that's not what we call the sizeof trick.
> Here is an example for checking for operator+:
> #include <boost/type_traits/remove_cv.hpp>
> #include <boost/static_assert.hpp>
> namespace detail {
> struct tag {};
> struct any { template <class T> any(T const&); };
> tag operator+(any const&, any const&);
> tag operator,(tag,int);

Wow, overloaded operator comma. I don't know whether to laugh or cry. In
any case, thanks for the code snippet :)


Boost list run by bdawes at, gregod at, cpdaniel at, john at