Boost logo

Boost :

From: Giovanni Bajo (giovannibajo_at_[hidden])
Date: 2002-04-24 15:11:01

----- Original Message -----
From: "Paul Mensonides" <pmenso57_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, April 24, 2002 8:55 PM
Subject: Re: [boost] Re: Quick Question...

> He wants to detect 'value' not type. I'm wasn't sure if he justed wanted
> detect if a available constant value of a certain name was present or a
> enumerator only. So, while I don't really see the utility of the entire
> this *will* detect if a type has a nested enumerator 'NAME':

Actually, detecting a constant would have been enough. When I write a
template, if there are several "user-configurable" options, instead of this:

template <typename PARM1, bool PARM2, int PARM3>
class MyTemplate { ... }

I prefer this:

template <class CONFIG>
class MyTemplate { ... }

Then the user writes:

struct Config
    typedef whatever PARM1;
    static const bool PARM2 = true;
    static const int PARM3 = 123;

Of course there are differences (lack of orthogonality, etc) but it works
fine for the scope of my application. Now, as a matter of fact, most
constant value are usually passed as enum {}, just like in:

struct Config
    typedef whatever PARM1;
    enum { PARM2 = 1, PARM3 = 123 };

since it's got less issues than "static const" (for example, you don't have
to define the member outside which is annoying).

The code I've asked for works very well to implement "optional parameters".
If I can detect if PARM10 does not exist, I can provide a default value for
it. Otherwise, every time I add a parameter I break source compatibility
with existing code. My current solution was:

struct Config : public DefaultConfig
{ ... }

So that I can change DefaultConfig, but I find the option to check for an
enum more "clean".

Thank you very much for the code.

Giovanni Bajo

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