Boost logo

Boost :

From: Ilya Buchkin (elias_at_[hidden])
Date: 2003-07-18 05:48:20


"Bill Seymour" <bill-at-the-office_at_[hidden]> wrote in message
news:3F1694DC.C44F44B5_at_pobox.com...
>
> Question: should I go back to template<int Scale> class decimal?
>
> Advantages: The assignment semantics issue goes away because
> the scale is part of the type.
>
> It's more like prior art.
>
> Disadvantages: The scale must be a constant expression.
>
> There are member template issues with some compilers.
>
> It won't work at all with MSVC v5 which can't deduce
> non-type template arguments. (OK, I could bite
> the bullet and maintain a non-Boost version
> for my own use at work; but I wouldn't be happy
> about it.)

Bill,

I have a suggestion that *might* work with MSVC 5 and enable
the template version. Unfortunately I do not have the beast (v.5),
so cannot check it, but it works on my v.6. Below is the code
example that illustrates the idea:

///////////// code begin ////////////////

#define __msvc_v51_pain_in_the_neck__ 1

#if __msvc_v51_pain_in_the_neck__

    struct __scale_traits_1 { enum { value_ = 1 }; };
    struct __scale_traits_2 { enum { value_ = 2 }; };
    #define SCALE_PARAM class AScale
    #define SCALE_VALUE AScale::value_
    #define SCALE_DECL(aScale) __scale_traits_##aScale

#else // i.e. all up-to-date compilers

    #define SCALE_PARAM int AScale
    #define SCALE_VALUE AScale
    #define SCALE_DECL(aScale) aScale

#endif

template< SCALE_PARAM >
struct decimal
    {
    static int scale() { return SCALE_VALUE; }
    };

// NOTES
// 1. below is declaration syntax which will be understood
// by both MSVC 5.1 and up-to-date compilers
// 2. all up-to-date people can simply write "decimal<N>"
// 3. all tests are to be written using syntax below,
// so that they can run everywhere

#include <iostream>
using namespace std;

int main()
    {
    decimal< SCALE_DECL(1) > d1;
    decimal< SCALE_DECL(2) > d2;
    cout << d1.scale() <<" "<< d2.scale() << endl;
    return 0;
    }

///////////// code end ////////////////
Would it work, and if so, Would it solve *all* issues of MSVC 5?

Regards
Ilya Buchkin
MetaCommunications Engineering


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