$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] boost.parameter - best practices
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-04-13 11:07:42
At Wed, 13 Apr 2011 07:50:52 +0200,
Christoph Heindl wrote:
> 
> 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.
Wow.  We designed this library so that you could avoid doing anything
like that!  That causes a lot of compile-time coupling: every time you
add a new keyword, you recompile the world.
> // 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?
I think so.  I think there may be a cure for this that we never got
around to implementing in the library.  If you want to make a small
reproducible test case and open a Trac ticket, there's a good chance
we can address it.
> So, is their any way to declare a parameter inside a class, through a
> typedef or similar? 
I don't know.  Did you try just using BOOST_PARAMETER_NAME at class
scope?  (I'm pretty sure that won't work but it's worth a shot).
> Let me illustrate
> 
> class x {
> public:
>   typedef boost::parameter::keyword<...> a;
> 
>   template<class Opts>
>   x(const Opts &o) {
>    _m_x = o[a | 10];
If "a" is a type, the above is illegal syntax (imagine substituting
"int" there).
>   }
> 
> };
> 
> 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?
Do you mean, any way to limit which keywords are allowed?  
Sure.  Oh, wow, I see that's been dropped from the documentation!  Yikes!
And I can't reconstruct it from memory (double Yikes)!
Daniel, can you try to explain how to use
boost::parameter::parameters<...>::type to do SFINAE?
(Sorry I couldn't help further)
-- Dave Abrahams BoostPro Computing http://www.boostpro.com