Boost logo

Boost :

From: Noah Stein (noah_at_[hidden])
Date: 2001-12-19 15:16:04


Your requirements seem fairly easy to implement conceptually. The reality
of completeness is the major hurdle. The basic idea would be, roughly:

template<class T, class S>
class semantic_number
{
        T value;

public:
        explicit semantic_number(const T& v) { value=v; }
        operator T() { return value; }

        semantic_number<T,S> operator+(const semantic_number<T,S>& rhs)
                { return semantic_number<T,S>(value+rhs.value); }
        semantic_number<T,S> operator+(const T& rhs)
                { return semantic_number<T,S>(value+rhs); }

        // etc. ...
}

This is just off the top of my head. And of course, you'd want to make sure
you'd cover all the valid operators. From that point, all you have to do is
create dummy classes that represent your partitioning of semantic space.

For best results, it would be preferable to replace the "const T&"
parameters with the types identified by the boost call traits library. I
haven't used explicit much, and the documentation I've seen hasn't indicated
that the operator T can be marked as such, but I vaguely remember that being
the case. Unfortunately, most of my books are currently in storage.

-- Noah

> -----Original Message-----
> From: Dale E. Strickler [mailto:DaleS_at_[hidden]]
> Sent: Wednesday, December 19, 2001 10:40 AM
> To: boost_at_[hidden]
> Subject: [boost] Looking for 'real' typedef.
>
>
> I have been searching through the boots library and have not yet
> found what
> I was looking for so I thought I would post a brief note to see
> if there is
> something in the works of if someone has a reference that might help.
>
> I would like to have variables that act like intrinsic types int
> and double
> but which are type unique in signatures. For instance I would like to do
> the following:
>
> some_sort_of_typedef<int> Apples_t;
> some_sort_of_typedef<int> Oranges_t;
>
> class cFruitMangager
> {
> public:
> // ....some constructors and such
> AppleFun(Apples_t a){ // do stuff with apples just like ints.};
> OrangeFun(Oranges_t o){ // do stuff with oranges just
> like ints. };
>
> // .. more stuff
> }
>
> void main(void)
> {
> cFruitMangager MyManager;
> Apple_t aApple;
> Orange_t aOrange;
>
> MyManager.AppleFun(aApple); // Ok!
> MyManager.AppleFun(aOrange); // Won't compile type
> mismatch.
>
> // also
> Orange_t newOrange=aOrange * 2 // ok!
> newOrange= aOrange + 1.03 // ok BUT does int math.
>
> Apple_t newApple=aApple + aOrange; // Won't compile type
> mismatch.
>
> newApple=aApple * 2 // ok!
> newApple= aOrange + 1.03 // ok BUT does int math.
> }
>
> Any ideas?
>
>
> Best Regards,
>
> Dale E. Strickler
> President and Sr. Consultant
> ___________________________________
> ___________________________________
> DES Software Engineering Consulting
> E-mail: DaleS_at_[hidden]
> Voice: 434-846-7003 (NOTE New area code!)
> FAX: 434-846-7040 (NOTE New area code!)
> Web: www.dessec.com
>
>
>
> Info: http://www.boost.org Send unsubscribe requests to:
> <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


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