Boost logo

Boost Users :

Subject: Re: [Boost-users] [parameter] Weird behavior with bools
From: David Abrahams (dave_at_[hidden])
Date: 2010-08-28 01:49:24


At Wed, 25 Aug 2010 22:48:57 -0700,
Ryan McConnehey wrote:
>
> I'm new to the parameter library and started with a simple example to
> get my feet wet. The first problem I'm having is with type
> restriction. The "name" variable is being restricted to a boolean
> type. This doesn't seem to be enforced since I can pass this variable a
> value of 15 and get this same value out. Currently my output has "name
> = 15" and I expected the output to be "name = 1". Did I not correctly
> enforce the type?

Looks like a bug to me. Daniel?

> The second problem is with the default value of my variable. I thought
> if the variable wasn't used then the third parameter, in the
> declaration, is used for instantiation of that variable. I thought that
> meant I could do this "m_name(args[_name])". The compiler gives an
> error saying the operator[] can't deduce the arguments. What did I not
> do that would allow this behavior.

Ditto, looks like a bug. If we don't already have tests for these
cases, we should.

> Thank you for your time in helping me out.
>
> Ryan
>
>
> BOOST_PARAMETER_NAME(name)
>
> struct myclass_impl
> {
> template <class ArgumentPack>
> myclass_impl(ArgumentPack const& args)
> : m_name(args[_name | false])
> //: m_name(args[_name]) //gives a compile error
> {
> std::cout << "name = " << m_name << std::endl;
> }
>
> private:
> int m_name;
> };
>
> struct myclass : public myclass_impl
> {
> BOOST_PARAMETER_CONSTRUCTOR(
> myclass, (myclass_impl), tag
> , (optional
> (name, (bool), bool(false)))) // no semicolon
> };
>
> int main(int argc, char* argv[])
> {
> myclass x(_name = 15);
>
> return 0;
> }

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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