Use initialization list with boost-parameter

146 views Asked by At

The following code will not compile because in the last call to 'demo' the compiler cannot deduce a type from the initialization-list.

#include <boost/parameter/name.hpp>
#include <boost/parameter/preprocessor.hpp>
#include <iostream>
#include <array>

BOOST_PARAMETER_NAME(arg)

BOOST_PARAMETER_FUNCTION(
    (void),
    demo,
    tag,
    (optional
    (arg, (std::array<int, 3>), (std::array<int,3>{}))
    )
    )
{
    std::cout << arg[1] << std::endl;
}


int main()
{   
    demo();
    demo(_arg=std::array<int,3>({1,2,3}));
    // 28:14: error: no match for 'operator=' 
    // (operand types are 'const boost::parameter::keyword<tag::arg>' 
    // and '<brace-enclosed initializer list>')
    demo(_arg={1,2,3});
}

Is there a way to combine initialization-lists with boost-parameter without adding an explicit call to the constructor of array?

0

There are 0 answers