Opened 9 years ago

Closed 9 years ago

#8603 closed Bugs (invalid)

BOOST_PARAMETER_CONSTRUCTOR with no required arugments

Reported by: james.hirschorn@… Owned by: Daniel Wallin
Milestone: Component: parameter
Version: Boost 1.53.0 Severity: Showstopper
Keywords: BOOST_PARAMETER_CONSTRUCTOR Cc:

Description

The following variation on the example from the boost::parameter tutorial, where the required parameter is changed to optional, fails to compile. myclass_impl is passed an empty agrument list.

#include <iostream>

#include <boost/parameter.hpp>


BOOST_PARAMETER_NAME(name)
BOOST_PARAMETER_NAME(index)

struct myclass_impl
{
    template <class ArgumentPack>
    myclass_impl(ArgumentPack const& args)
    {
        std::cout << "name = " << args[_name]
                  << "; index = " << args[_index]
                  << std::endl;
    }
};

struct myclass : myclass_impl
{
    BOOST_PARAMETER_CONSTRUCTOR(
        myclass, (myclass_impl), tag
            ,   (optional (name, *) (index, *)
                )
    ) // no semicolon
};

int main(int argc, char * argv[])
{
    myclass C(_name="hello", _index=0);
}

Compilation output:

In instantiation of 'myclass_impl::myclass_impl(const ArgumentPack&) [with ArgumentPack = boost::parameter::aux::empty_arg_list]':
...

Attachments (1)

main.cpp (624 bytes ) - added by james.hirschorn@… 9 years ago.
example reproducing bug

Download all attachments as: .zip

Change History (3)

by james.hirschorn@…, 9 years ago

Attachment: main.cpp added

example reproducing bug

comment:1 by James.Hirschorn@…, 9 years ago

This bug should be closed. It was pointed out on the devel mailing list that optional arguments to BOOST_PARAMETER_CONSTRUCTOR must be extraced with a '|' default specifier (e.g. arg[_name | ""]).

However, this should still be explicitly stated in the documentation.

comment:2 by viboes, 9 years ago

Milestone: To Be Determined
Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.