Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-08-21 23:55:05


"Andy Little" <andy_at_[hidden]> writes:

> For addition you would need to do this:
>
> nocast(a) + nocast(b);
>
> for multiplication
>
> nocast(a) * nocast(b);

Seems like one should be enough to prevent promotion and implicit
combinations:

 nocast(a) * b

> You could make this a general purpose utility:
>
> template <typename T>
> struct no_caster{
> T t;
> /*...*/
> };

Alright, now you've gone too far. The name is taken.
http://www.fender.com/products/search.php?partno=0150302867

> template <typename T1, typename T2>
> typename boost:enable_if<
> boost::is_same<T1, T2>,T1
>>::type
>
> operator Op (nocaster<T1> ,nocaster<T2>);

You might do it with expression templates to get:

     x [strict]= y + z * b;

Or just encode the restriction in the type of x.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk