Boost logo

Boost Users :

Subject: [Boost-users] boost.parameter - best practices
From: Christoph Heindl (christoph.heindl_at_[hidden])
Date: 2011-04-13 01:50:52


Hi,

I have a set of classes that offer named parameter enabled
constructors through the use of argument packs. Currently I have one
huge header container all the available arguments of all classes.

// params.h
namespace geo {
  namespace keywords {
    BOOST_PARAMETER_NAME(a)
    BOOST_PARAMETER_NAME(b)
  }
}

// thing.h
namespace geo {
  class thing {
  public:
    template<class Opts>
    thing(const Opts &o) {
     _m_x = o[Keywords::_a | 10];
     //etc..
    }
  };
}

// thing2.h
namespace geo {
  class thing2 {
  public:
    template<class Opts>
    thing2(const Opts &o) {
     _m_x = o[Keywords::_b | 10];
     //etc..
    }
  };
}

First question: I'd like to place the BOOST_PARAMETER_NAME keywords as
close to its usage as possible. I.e. I'd like to place
BOOST_PARAMETER_NAME(a) on top of thing.h. If I do so, I think that
over time other classes will start to have their own
BOOST_PARAMETER_NAME(a) constructs in their header files, which I
think would lead to multiple defined symbols if two class headers are
included in the same translation unit, correct?

So, is their any way to declare a parameter inside a class, through a
typedef or similar? Let me illustrate

class x {
public:
  typedef boost::parameter::keyword<...> a;

  template<class Opts>
  x(const Opts &o) {
   _m_x = o[a | 10];
  }

};

x my_x(x::a = 5);

If that is not possible, is there any way to limit the template
parameter Opts in the above example to set of possible parameters?

Best regards,
Christoph


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net